You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the functions readAccReg() and readMagReg(), there is a Wire.endTransmission() after the Wire.requestFrom(). That should not be there. The Wire.endTransmission() is only used when writing data.
It is not a big problem, but the Wire.endTransmission() will sent the sensor address to the I2C bus and the sensor will aknowledge. It does no harm, but it is unnecessary.
In the functions readAcc() and readMag(), there is a timeout after Wire.requestFrom(). That timeout is not needed. The Wire.requestFrom() waits until the I2C transmission has completely finished. After that, the received data is in a buffer in the Wire library. The Wire.available() shows how many bytes there are in that buffer.
The timeout is not needed, but in case there was a I2C bus error, it does detect that not all bytes are received and it does return with an error.
The return value of Wire.requestFrom() or the Wire.available() could be be used once to check if the correct number of bytes was received or if a bus error did occur.
The text was updated successfully, but these errors were encountered:
I just noticed this pull-request: #2
A while-loop to wait for something after a Wire.requestFrom() is wrong and that was replaced with nonsense code with millis() and a timeout.
Explanation: Common-mistakes#1
In the functions readAccReg() and readMagReg(), there is a Wire.endTransmission() after the Wire.requestFrom(). That should not be there. The Wire.endTransmission() is only used when writing data.
It is not a big problem, but the Wire.endTransmission() will sent the sensor address to the I2C bus and the sensor will aknowledge. It does no harm, but it is unnecessary.
In the functions readAcc() and readMag(), there is a timeout after Wire.requestFrom(). That timeout is not needed. The Wire.requestFrom() waits until the I2C transmission has completely finished. After that, the received data is in a buffer in the Wire library. The Wire.available() shows how many bytes there are in that buffer.
The timeout is not needed, but in case there was a I2C bus error, it does detect that not all bytes are received and it does return with an error.
The return value of Wire.requestFrom() or the Wire.available() could be be used once to check if the correct number of bytes was received or if a bus error did occur.
The text was updated successfully, but these errors were encountered: