Added .5MHz recovery clock to the AVRISP programmer project when in ISP programming...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / ISP / ISPProtocol.c
index 33ccbf9..e0eb441 100644 (file)
@@ -62,7 +62,14 @@ void ISPProtocol_EnterISPMode(void)
        uint8_t ResponseStatus = STATUS_CMD_FAILED;\r
        \r
        CurrentAddress = 0;\r
        uint8_t ResponseStatus = STATUS_CMD_FAILED;\r
        \r
        CurrentAddress = 0;\r
+       \r
+       /* Set up the synchronous USART to generate the recovery clock on XCK pin */\r
+       UBRR1  = (F_CPU / 500000UL);\r
+       UCSR1B = (1 << TXEN1);\r
+       UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);\r
+       DDRD  |= (1 << 5);\r
 \r
 \r
+       /* Perform execution delay, initialize SPI bus */\r
        ISPProtocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS); \r
        SPI_Init(ISPTarget_GetSPIPrescalerMask() | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER);\r
 \r
        ISPProtocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS); \r
        SPI_Init(ISPTarget_GetSPIPrescalerMask() | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER);\r
 \r
@@ -118,6 +125,12 @@ void ISPProtocol_LeaveISPMode(void)
        SPI_ShutDown();\r
        ISPProtocol_DelayMS(Leave_ISP_Params.PostDelayMS);\r
 \r
        SPI_ShutDown();\r
        ISPProtocol_DelayMS(Leave_ISP_Params.PostDelayMS);\r
 \r
+       /* Turn off the synchronous USART to terminate the recovery clock on XCK pin */\r
+       UBRR1  = (F_CPU / 500000UL);\r
+       UCSR1B = (1 << TXEN1);\r
+       UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);\r
+       DDRD  &= ~(1 << 5);\r
+\r
        Endpoint_Write_Byte(CMD_LEAVE_PROGMODE_ISP);\r
        Endpoint_Write_Byte(STATUS_CMD_OK);\r
        Endpoint_ClearIN();\r
        Endpoint_Write_Byte(CMD_LEAVE_PROGMODE_ISP);\r
        Endpoint_Write_Byte(STATUS_CMD_OK);\r
        Endpoint_ClearIN();\r