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/Arduino#1311
This commit is contained in:
Kevin Chang 2014-02-17 19:49:44 -08:00
parent 4e334b2e96
commit c92206909d
1 changed files with 4 additions and 2 deletions

View File

@ -125,8 +125,10 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop
if (readed + 1 == quantity)
TWI_SendSTOPCondition( twi);
TWI_WaitByteReceived(twi, RECV_TIMEOUT);
rxBuffer[readed++] = TWI_ReadByte(twi);
if (TWI_WaitByteReceived(twi, RECV_TIMEOUT))
rxBuffer[readed++] = TWI_ReadByte(twi);
else
break;
} while (readed < quantity);
TWI_WaitTransferComplete(twi, RECV_TIMEOUT);