Do not reply with NAK on last byte

At least the bcm2835 (Raspberry Pi 3) I2C/SMBus master has problems
when replying with a NAK to the last byte written to a slave device.

Fix this by replying with NAK one byte later.
This commit is contained in:
Olaf Rempel 2021-02-20 21:56:26 +01:00
parent baf5a895b5
commit 559a403836
2 changed files with 14 additions and 16 deletions

View File

@ -10,11 +10,11 @@ Currently the following AVR MCUs are supported:
AVR MCU | Flash bytes used (.text + .data) | Bootloader region size AVR MCU | Flash bytes used (.text + .data) | Bootloader region size
--- | --- | --- --- | --- | ---
attiny85 | 956 (0x3BC) | 512 words attiny85 | 954 (0x3BA) | 512 words
atmega8 | 802 (0x322) | 512 words atmega8 | 786 (0x312) | 512 words
atmega88 | 826 (0x33A) | 512 words atmega88 | 810 (0x32A) | 512 words
atmega168 | 826 (0x33A) | 512 words atmega168 | 810 (0x32A) | 512 words
atmega328p | 826 (0x33A) | 512 words atmega328p | 810 (0x32A) | 512 words
(Compiled on Ubuntu 18.04 LTS (gcc 5.4.0 / avr-libc 2.0.0) with EEPROM and LED support) (Compiled on Ubuntu 18.04 LTS (gcc 5.4.0 / avr-libc 2.0.0) with EEPROM and LED support)

14
main.c
View File

@ -21,7 +21,7 @@
#include <avr/boot.h> #include <avr/boot.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#define VERSION_STRING "TWIBOOT v3.1" #define VERSION_STRING "TWIBOOT v3.2"
#define EEPROM_SUPPORT 1 #define EEPROM_SUPPORT 1
#define LED_SUPPORT 1 #define LED_SUPPORT 1
@ -400,14 +400,9 @@ static uint8_t TWI_data_write(uint8_t bcnt, uint8_t data)
uint8_t pos = bcnt -4; uint8_t pos = bcnt -4;
buf[pos] = data; buf[pos] = data;
if (pos >= (sizeof(buf) -2)) if (pos >= (SPM_PAGESIZE -1))
{ {
ack = 0x00; if (cmd == CMD_ACCESS_FLASH)
}
if ((cmd == CMD_ACCESS_FLASH) &&
(pos >= (sizeof(buf) -1))
)
{ {
#if (USE_CLOCKSTRETCH) #if (USE_CLOCKSTRETCH)
write_flash_page(); write_flash_page();
@ -415,6 +410,9 @@ static uint8_t TWI_data_write(uint8_t bcnt, uint8_t data)
cmd = CMD_WRITE_FLASH_PAGE; cmd = CMD_WRITE_FLASH_PAGE;
#endif #endif
} }
ack = 0x00;
}
break; break;
} }