Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69a74b2

Browse files
neophobfacchinm
authored andcommitted
fix bug #1354: I2C/TWI Library: Buffer Overflow
1 parent 6c861d8 commit 69a74b2

File tree

1 file changed

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

1 file changed

+8
-2
lines changed

libraries/Wire/src/utility/twi.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,14 @@ ISR(TWI_vect)
509509
break;
510510
case TW_SR_DATA_NACK: // data received, returned nack
511511
case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack
512-
// nack back at master
513-
twi_reply(0);
512+
// We replied a nack, this happens when the buffer overflows.
513+
// After this interrupt we don't get a TW_SR_STOP interrupt, so
514+
// clean up now
515+
516+
// Discard the data, it is incomplete
517+
twi_rxBufferIndex = 0;
518+
// ack future responses and leave slave receiver state
519+
twi_releaseBus();
514520
break;
515521

516522
// Slave Transmitter

0 commit comments

Comments
 (0)