Skip to content

Commit 12b5422

Browse files
committed
SAM Wire: fixed NACK/timeout behavior of requestFrom() and available()
"readed" is no longer incremented in requestFrom() if TWI_WaitByteReceived() gets a NACK or times out. This corrects the behavior (return values) of requestFrom() and available() to match the Arduino reference. Fixes arduino#1311
1 parent 70c6a78 commit 12b5422

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libraries/Wire/Wire.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop
125125
if (readed + 1 == quantity)
126126
TWI_SendSTOPCondition( twi);
127127

128-
TWI_WaitByteReceived(twi, RECV_TIMEOUT);
129-
rxBuffer[readed++] = TWI_ReadByte(twi);
128+
if (TWI_WaitByteReceived(twi, RECV_TIMEOUT))
129+
rxBuffer[readed++] = TWI_ReadByte(twi);
130+
else
131+
break;
130132
} while (readed < quantity);
131133
TWI_WaitTransferComplete(twi, RECV_TIMEOUT);
132134

0 commit comments

Comments
 (0)