From ab195ab1da1da75a3a23d47b56c66d14803a9de3 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Wed, 10 Feb 2010 04:02:10 +0000 Subject: Added .5MHz recovery clock to the AVRISP programmer project when in ISP programming mode to correct mis-set fuses. Fixed AVRISP project not extending the command delay after each successful page/word/byte program. --- Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c | 13 +++++++++++++ Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'Projects/AVRISP-MKII/Lib/ISP') diff --git a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c index 33ccbf91e..e0eb44107 100644 --- a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c +++ b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c @@ -62,7 +62,14 @@ void ISPProtocol_EnterISPMode(void) uint8_t ResponseStatus = STATUS_CMD_FAILED; CurrentAddress = 0; + + /* Set up the synchronous USART to generate the recovery clock on XCK pin */ + UBRR1 = (F_CPU / 500000UL); + UCSR1B = (1 << TXEN1); + UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1); + DDRD |= (1 << 5); + /* Perform execution delay, initialize SPI bus */ ISPProtocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS); SPI_Init(ISPTarget_GetSPIPrescalerMask() | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER); @@ -118,6 +125,12 @@ void ISPProtocol_LeaveISPMode(void) SPI_ShutDown(); ISPProtocol_DelayMS(Leave_ISP_Params.PostDelayMS); + /* Turn off the synchronous USART to terminate the recovery clock on XCK pin */ + UBRR1 = (F_CPU / 500000UL); + UCSR1B = (1 << TXEN1); + UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1); + DDRD &= ~(1 << 5); + Endpoint_Write_Byte(CMD_LEAVE_PROGMODE_ISP); Endpoint_Write_Byte(STATUS_CMD_OK); Endpoint_ClearIN(); diff --git a/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c b/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c index c9822d0a6..267e51850 100644 --- a/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c +++ b/Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c @@ -139,6 +139,9 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1 ProgrammingStatus = ISPTarget_WaitWhileTargetBusy(); break; } + + if (ProgrammingStatus == STATUS_CMD_OK) + TimeoutMSRemaining = COMMAND_TIMEOUT_MS; return ProgrammingStatus; } @@ -159,10 +162,7 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void) } while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining); - if (!(TimeoutMSRemaining)) - return STATUS_RDY_BSY_TOUT; - else - return STATUS_CMD_OK; + return ((TimeoutMSRemaining) ? STATUS_CMD_OK : STATUS_RDY_BSY_TOUT); } /** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the -- cgit v1.2.3