Skip to content

Commit daa4a32

Browse files
committed
Fix twi zero bytes read error
1 parent 321fca0 commit daa4a32

File tree

1 file changed

+11
-2
lines changed
  • libraries/Wire/src/utility

1 file changed

+11
-2
lines changed

Diff for: libraries/Wire/src/utility/twi.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void (*twi_onSlaveReceive)(uint8_t*, int);
6060

6161
static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
6262
static volatile uint8_t twi_masterBufferIndex;
63-
static volatile uint8_t twi_masterBufferLength;
63+
static volatile int8_t twi_masterBufferLength;
6464

6565
static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH];
6666
static volatile uint8_t twi_txBufferIndex;
@@ -552,7 +552,16 @@ ISR(TWI_vect)
552552
__attribute__ ((fallthrough));
553553
case TW_MR_SLA_ACK: // address sent, ack received
554554
// ack if more bytes are expected, otherwise nack
555-
if(twi_masterBufferIndex < twi_masterBufferLength){
555+
if (twi_masterBufferLength == -1){
556+
// required data length 0 bytes, no need to get data
557+
if (twi_sendStop){
558+
twi_stop();
559+
} else {
560+
twi_inRepStart = true;
561+
TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
562+
twi_state = TWI_READY;
563+
}
564+
}else if(twi_masterBufferIndex < twi_masterBufferLength){
556565
twi_reply(1);
557566
}else{
558567
twi_reply(0);

0 commit comments

Comments
 (0)