marcmerlin / IoTuz

IoTuz driver for ESP32 based LCA 2017 IoTuz board, also can be used as a demo on an espressif WROVER
Apache License 2.0
28 stars 7 forks source link

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

Closed Koepel closed 6 years ago

Koepel commented 7 years ago

In the file "IoTuz.cpp", in the function "i2cexp_read()", there is a while-loop after the Wire.requestFrom(). That while-loop can be removed, there is nothing to wait for.

When the Wire.requestFrom() returns, the I2C transaction has completely finished and the received data is waiting in a buffer in the Wire library.

marcmerlin commented 7 years ago

Thanks. I inherited that code and didn't know that bit. I'm on vacation but will change it when I can.

Out of curiosity, what board are you using the code on, did you have any issues with it?

Koepel commented 7 years ago

I did not use the code. I try to improve the use of the Arduino Wire library, because the wrong use of the Wire library is copied so many times.

It might have negative consequences in a very rare situation. If the Wire.requestFrom() detects a bus error or collision in a multi-master bus, it probably returns that zero bytes have been received. In that case the Wire.available() also returns zero, and that while-loop will halt the sketch.

marcmerlin commented 6 years ago

Fixed by https://github.com/marcmerlin/IoTuz/commit/95f53be6569c68f7fbef491bb36082870f82d629 , soryr for the delay