sparkfun / SparkFun_SX1509_Arduino_Library

Arduino library for the SX1509 16-I/O GPIO expander.
44 stars 38 forks source link

No need to wait for data after Wire.requestFrom() #2

Closed Koepel closed 2 years ago

Koepel commented 8 years ago

The timeout or the while-loop to wait for something is not needed after Wire.requestFrom().

When the Wire.requestFrom() function returns, the I2C transaction has completely finished and the received data is in the receive buffer in the Wire library. The Wire.read() only reads data from that buffer.

When there was a I2C bus error or I2C collision, there would be less bytes received, and that while-loop would halt the sketch.

fluffy commented 5 years ago

I'm running the 2.0.1 version which seems to be what Arduino IDE downloads as latest. I have a few other I2C things on the same bug and my sketch (running on a SAMD51) locks up in this loop within a few minutes of starting. Be great to see a fix make it into a release.