Open Koepel opened 2 years ago
Koepel,
Thank you for bringing this to our attention and the in-depth explanation. The example programs seen in this repository were written by FTDI/Bridgetek. Therefore, fixing this bug in all the example sketches is time-consuming and low-priority at the moment.
In many files where
Wire.requestFrom()
is used, I see the comment: "/ blocking call - at least one byte must be available /" That is not how the Arduino Wire library works.The
Wire.requestFrom()
does the whole I2C session and that function itself is blocking. It only returns when the I2C session has completely finished. After that, the received data is in a buffer in the Wire library. TheWire.read()
andWire.available()
operate on that buffer.So there is no need to wait for something. The data is in the buffer, or not.
Example to check if there was data:
After a
Wire.requestFrom()
, there is no need to wait for something. I call that common mistake number 1. See also my alternative explanation of the Wire library.