-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Wire lib hangs when scanning i2c in Wire.endTransmission() #194
Comments
Hi @erniberni Your program is getting hung in one of two places: I've reviewed Arduino's I2CM implementation and the Wire library calls that are made to perform a scan, and there are a few ways that you can end up locked up.
Unfortunately, there is no timeout concept in any of the Arduino board I2C drivers, so unless you have a 100% perfect setup, you can expect an application hangup in the event of certain classes of errors. Even if you have a watchdog and the chip resets, there is no guarantee that the error condition will disappear (the slave could still be holding down lines). In Arduino's defense, timeouts aren't part of the I2C spec, but then again, they don't even call it I2C, and it is not difficult to tease an I2C lockup out of most configurations. My philosophy is that I2C failures should not block your application, so timeouts should be employed to allow the user to decide what to do in the event of I2C conditions that led to a timeout. Some community members have added I2C timeouts for the various boards. For the SAMD21, you can check out RIOT OS's I2C driver for the SAMD21, however it also does not implement an I2CM driver that is fully robust, so I am working through a patch for them as well at the moment. It also does not conform to the Wire API, so it is not plug and play by any means. All in all, the SAMD21 I2C peripheral is a complex beast that is almost too "smart" for its own good. I have yet to see anyone successfully implement a robust driver for it, and I believe this is mostly because the documentation for the peripheral is sometimes vague, conflicting, and leaves certain things out. I feel like I am getting pretty close with a combination of Arduino's driver, RIOT's driver, and my own custom driver that I wrote, so hopefully in the not too distant future, I can provide a standalone I2CM library that can be used to substitute wire or otherwise help to update the Arduino SAMD core and wire libraries. |
@spiderkeys |
Whoops, yea I meant pullup. Don't know what possessed me to write that;
will edit my post to prevent confusion for anyone else.
|
@erniberni any updates on this? |
No, I didn't find a solution. |
improve tinyusb samd driver
my Mega2560 hangs on endTransmission() when slave device is off, It seems unpowered device forms pull-down on i2c lines, but this is not good if firmware is toatlly hangs. |
I'm running into the same issue, any fix for this? |
Hi,
I tried the well known i2c scanner found on Arduino playground with a Feather M0.
Unfortunately the program hangs while testing
error = Wire.endTransmission();
In many libraries (for ex. the BME280 lib) this test is used to check if the sensor (based on it's i2c address) is present.
On Arduino and ESP the i2c scanner is working.
The text was updated successfully, but these errors were encountered: