Skip to content

Commit c922069

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 #1311
1 parent 4e334b2 commit c922069

File tree

1 file changed

+4
-2
lines changed
  • hardware/arduino/sam/libraries/Wire

1 file changed

+4
-2
lines changed

hardware/arduino/sam/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)