Fixed issues with EEPROM and FLASH ISP programming in the AVRISP project.
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / ISP / ISPProtocol.c
index 59a77e5..33ccbf9 100644 (file)
@@ -198,14 +198,15 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
                        \r
                        /* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
                         * or low byte at the current word address */\r
-                       Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
+                       if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
+                         Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
 \r
                        /* Check to see the write completion method, to see if we have a valid polling address */\r
                        if (!(PollAddress) && (ByteToWrite != PollValue))\r
                        {\r
                                if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
                                  Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
-                                 \r
+\r
                                PollAddress = (CurrentAddress & 0xFFFF);                                \r
                        }               \r
 \r
@@ -239,17 +240,17 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
                {\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
                        uint8_t ByteToWrite = *(NextWriteByte++);\r
-               \r
-                       if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
-                         Write_Memory_Params.ProgrammingCommands[0] |=  READ_WRITE_HIGH_BYTE_MASK;\r
-                       else\r
-                         Write_Memory_Params.ProgrammingCommands[0] &= ~READ_WRITE_HIGH_BYTE_MASK;                     \r
                          \r
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
                        SPI_SendByte(CurrentAddress & 0xFF);\r
                        SPI_SendByte(ByteToWrite);\r
                        \r
+                       /* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
+                        * or low byte at the current word address */\r
+                       if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
+                         Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
+\r
                        if (ByteToWrite != PollValue)\r
                        {\r
                                if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r