From 559a403836e8d91a2d5b962e9541af679150b7a9 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sat, 20 Feb 2021 21:56:26 +0100 Subject: [PATCH] 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. --- README.md | 10 +++++----- main.c | 20 +++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1a40433..1e7e9b0 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ Currently the following AVR MCUs are supported: AVR MCU | Flash bytes used (.text + .data) | Bootloader region size --- | --- | --- -attiny85 | 956 (0x3BC) | 512 words -atmega8 | 802 (0x322) | 512 words -atmega88 | 826 (0x33A) | 512 words -atmega168 | 826 (0x33A) | 512 words -atmega328p | 826 (0x33A) | 512 words +attiny85 | 954 (0x3BA) | 512 words +atmega8 | 786 (0x312) | 512 words +atmega88 | 810 (0x32A) | 512 words +atmega168 | 810 (0x32A) | 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) diff --git a/main.c b/main.c index 1ec8249..1f6cde7 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,7 @@ #include #include -#define VERSION_STRING "TWIBOOT v3.1" +#define VERSION_STRING "TWIBOOT v3.2" #define EEPROM_SUPPORT 1 #define LED_SUPPORT 1 @@ -400,20 +400,18 @@ static uint8_t TWI_data_write(uint8_t bcnt, uint8_t data) uint8_t pos = bcnt -4; buf[pos] = data; - if (pos >= (sizeof(buf) -2)) - { - ack = 0x00; - } - - if ((cmd == CMD_ACCESS_FLASH) && - (pos >= (sizeof(buf) -1)) - ) + if (pos >= (SPM_PAGESIZE -1)) { + if (cmd == CMD_ACCESS_FLASH) + { #if (USE_CLOCKSTRETCH) - write_flash_page(); + write_flash_page(); #else - cmd = CMD_WRITE_FLASH_PAGE; + cmd = CMD_WRITE_FLASH_PAGE; #endif + } + + ack = 0x00; } break; }