-
Notifications
You must be signed in to change notification settings - Fork 7.6k
I2C broken with version 2.0.1 #5875
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
This is likely a bug in the libraries that are using Wire outside of the expected / supported patterns. Another Adafruit library was recently found to have a similar bug and likely these are impacted the same. @ladyada can you review? |
I can confirm that Adafruit SCD30 library ( https://github.com/adafruit/Adafruit_SCD30 ) is also broken in 2.0.1. |
hiya we now use a wrapper library for i2c for sensors like the SCD30 https://github.com/adafruit/Adafruit_BusIO however, the scd-30 does not use repeated start that we know of iirc @me-no-dev has been doing the most work on i2c and repeated start. |
@FStefanni it looks like the u-blox library you reference is doing multiple starts in a single block and may have a bug. There may also be bugs in the I2C code in this repository though. |
Just to add some info that this might be related to repeated start and/or clock stretching, tested behavior real quick with a BME280 (which does none of that) using library example. Also tested SCD30 with library example just to verify behavior above. Used a Metro ESP32-S2 and a HUZZAH ESP32.
So it's not broken for everything. Hopefully this info can help narrowing in on issue. |
I2C is not broken. Some stuff changed. Many many libs out there are not correctly done. |
Hi, I reported the issue to the Sparkfun GNSS lib. Nevertheless it seems strange imho that so many libraries broke... I hope it will be fixed quickly, since we use this stuff at work. Regards. |
I agree with @Jason2866 here. The library in this repo works fine as long as it is used as per documentation (official Arduino documentation that is). Unfortunately many libs do the calls in some strange order, like wrapping |
Hi All, I've been investigating the failures with the SparkFun u-blox library on v2.0.1 of the core, and I believe the key issue is actually I2C clock stretching (not I2C restarts - or a lack of proper I see similar badness with the SparkFun Qwiic Button. It uses clock stretching - but does not use restarts when communicating on I2C. More details are here: sparkfun/SparkFun_u-blox_GNSS_Arduino_Library#77 (comment) Right now, I believe the name of this issue should be changed to "I2C broken with version 2.0.1 on devices which use clock stretching". Best wishes, |
This commit causes the break. I'm still digging but a Code to replicate issue:
Below is at this commit (pre thread safe I2C commit): I should have had my core debug turned on. This appears to be by design:
|
Is it possible the condition for triggering that is inverted? |
Here is my little experience on this matter: I have tested 2.0.1 using these libraries and the devices work as expected, probably they don't use clock stretching. I have tested it just for some minutes though. adafruit/Adafruit VEML6070 Library@^1.0.6 |
@garageeks - I'm speaking at the edge of my knowledge here but testing or listing individual libraries could be counterproductive. I suspect you will find that devices that don't require repeated-starts (such as the OLED library) work just fine, whereas other devices that use repeated starts fail. If you can find a library that does use repeated starts, and works, that would be really interesting. |
The way I2C is designed in v2.0.1 no bytes are written to the bus with an
This gets close as we have the correct repeated start condition, but we end up with some very weird fits and starts before the 2nd start command is issued: This is not surprising as it clearly breaks the start/write/write/stop flow the driver expects. I'm trying to pin down where this is occurring in the IDF but I suspect it may need a |
@nseidle that was the same in the previous driver. It has to do with the fact that the ESP32 I2C peripheral sends data ONLY when the transaction ends with STOP, so in the case of repeated start, you endTransmission(false) and then you requestFrom to issue the repeated start and send everything to the device. The peripheral requires that and it's not just some weird decision we made. |
Also to say, the devices that I have and use repeated start (also some that others including @ladyada have tested) work fine. I do not have a device to test for stretching (where the device holds SCL low) |
@me-no-dev it might be good to pick up a clock-stretching chip to test against since they are often edge-cases in I2C implemenations. BNO055, PN532, CCS811 are ones you can find easily. i can send you some if there aren't any available where you are at. |
@ladyada I ordered BNO055 and CCS811. Will test them when they come and report back |
I have a CCS811 sensor and a PN532 card reader laying around, I can test it if you could provide some directions. |
Hm I don't recall that the CCS811 was particularly tricky to address. Is it possible that the latest code now also has some functionality added to get out of a hung I2C bus? On ESP8266 it seems like the set value is in usec, right? A lot of sources found via Google suggest to set it to "1000" on the ESP8266, so a timeout of 1 msec should be the same. |
timeout has a slightly different meaning here. it's the amount of time to wait on the bus to complete the transaction. 8266 has software I2C library, so things there are different :) |
Clock stretching fix: #5910 |
Just tested those changes with the ESP32 / SCD30 combo that was previously failing. It is now working. |
ESP32 with u-blox works great. Clock stretching looks fixed. And unless I'm mistaken, the writes with repeated start issue is also alleviated. I still understanding how fix #5910 affects this but either way, the communication looks great. Thanks @me-no-dev. |
It should not do anything for multiple repeated starts, but stretching and other timing related issues should be fixed :) merging... |
It was found that when I2C device is holding the clock LOW, ESP32 master is failing to wait for the clock to be released. Fixes: #5875 Fixes: sparkfun/SparkFun_u-blox_GNSS_Arduino_Library#77
Hi, thank you for the fix. Regards. |
Yes. I just ran into this same error. Any idea when a new official release will be out that incorporates this? |
in a couple of weeks |
Hardware:
Board: ESP32 Dev Module, ESP32 Wrover
Core Installation version: 2.0.1
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10
Description:
Hi,
I have tested the two boards, with two I2C libraries, namely:
The tests have been performed with the core installation version 2.0.0 and 2.0.1.
All tests succeeded with version 2.0.0, but failed with version 2.0.1, since they stucked in the setup.
Since the only difference was the core version, I suppose version 2.0.1 introduced a bug in the I2C management.
Please note that I have also tested some basic functionalities of the Adafruit_SSD1306 lib (it is a display), and it worked, so maybe the possible
bug is related to reading from the I2C.
Can you please confirm whether you have the same issues?
Thank you,
regards.
Debug Messages:
Log with ESP32 Dev Module and lib SparkFun_u-blox_GNSS_Arduino_Library.
The text was updated successfully, but these errors were encountered: