Skip to content

Commit

Permalink
Fix twi zero bytes read error
Browse files Browse the repository at this point in the history
  • Loading branch information
xl-or committed Sep 8, 2024
1 parent 321fca0 commit daa4a32
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libraries/Wire/src/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void (*twi_onSlaveReceive)(uint8_t*, int);

static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
static volatile uint8_t twi_masterBufferIndex;
static volatile uint8_t twi_masterBufferLength;
static volatile int8_t twi_masterBufferLength;

static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH];
static volatile uint8_t twi_txBufferIndex;
Expand Down Expand Up @@ -552,7 +552,16 @@ ISR(TWI_vect)
__attribute__ ((fallthrough));
case TW_MR_SLA_ACK: // address sent, ack received
// ack if more bytes are expected, otherwise nack
if(twi_masterBufferIndex < twi_masterBufferLength){
if (twi_masterBufferLength == -1){
// required data length 0 bytes, no need to get data
if (twi_sendStop){
twi_stop();
} else {
twi_inRepStart = true;
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
twi_state = TWI_READY;
}
}else if(twi_masterBufferIndex < twi_masterBufferLength){
twi_reply(1);
}else{
twi_reply(0);
Expand Down

0 comments on commit daa4a32

Please sign in to comment.