-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Wrong use of Wire library #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jrowberg old but missing feedback :( |
@Koepel why not make a pull request? I've noticed you been bringing this up on several MPU6050 libraries and I've actually made the necessary changes on my end but I feel like this might go over alot of developers heads especially if they encounter errors or weird behaviour. |
@ONLYstcm There is too much going on. Without the bugs the FastWire can be removed. The Arduino Wire library does not have timeouts so all the timeouts can be removed. But then there is a Teensy I2C library that does have timeouts. For that Teensy library it would be nice to keep the timeouts. Then there is a NBWIRE which uses some of the source of the Arduino Wire library. But I don't know if bugfixes from the Arduino library made it into NBWIRE. The FastWire and NBWIRE are only for AVR chips. It all started with the Arduino Wire library which does not have timeouts. The library became a standard from the start, and everything went haywire (pun intended). They could have fixed that problem for the SAMD processors, but also that Arduino Wire library does not have timeouts. The Arduino reference for the Wire library was not good. That is improved, and it continues to improve over the years with very small steps. My alternative explanation still makes a few things more clear, which should already be clear by reading the reference. |
@Koepel I've already read your wiki and actually used that to make necessary changes on one of the libraries that I was using. But yeah please do go on, this will be a good reference point for others as well. |
A few issues have already been reported about code with the Wire functions of I2Cdev.cpp.
#252 (timeout is not in Arduino library)
#181 (adding a repeated start)
#76 (data length)
In 5 places, the Wire.requestFrom() is followed by a Wire.endTransmission(). That causes an extra I2C transaction with the address on the I2C bus and the Slave acknowledging. The Wire.requestFrom() is a complete I2C transaction on its own, and should not be followed by a Wire.endTransmission().
A timeout for getting data after Wire.requestFrom() is not needed. When the Wire.requestFrom() returns, the I2C transaction has completely finished and the received data is in the receive buffer in the Wire library. That data can be read with Wire.read(). In case there was a bus error or a collision, the return value of Wire.requestFrom() or Wire.available() will be less than the number of requested byte (it will most likely be zero). A single check for that error or collision is possible.
The text was updated successfully, but these errors were encountered: