-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
ESP-IDF v5.3 I2C Old driver working, new driver not. (IDFGH-13508) #14401
Comments
May you check the scl/sda data with logic analyzer to see what exactly happens?And probably compared with old one. From the log and description, I guess there might happen with long stretch. |
@western-hoolock Check if this helps: #14129 (comment) |
Unfortunately I don't have a logic analyzer or access to one. The BQ27441 datasheet mentions that it can do clock stretching up to 4ms, in both the new and old driver examples I posted I set it to 5ms to be on the safe side: Old driver: New driver: One difference I noticed though is that the old driver takes APB clock cycles as units and the new driver takes the number of microseconds. But yeah, I wish I had access to a logic analyzer so I could actually confirm that the new driver actually respects the allowed timeout for clock stretching. |
The issue seems similar at first but eventually it turns out the root cause of the issue was the ESP-IDF not supporting clock stretching above ~12ms while the I2C slave that person uses clearly states it can stretch up to 20ms. This is not the case in my situation, the BQ27441's datasheet states it can stretch up to 4ms, so to be safe I have set it to 5ms in both the old and new I2C driver examples. |
@mythbuster5 |
Answers checklist.
General issue report
Environment: PlatformIO with v5.3 and an ESP32-WROVER-E on a custom board and a Texas Instruments BQ27441 Fuel Gauge and external 4.7k SCL/SDA pull-up resistors.
I wrote some code that uses the deprecated I2C <i2c.h> driver, which works fine at 400kHz:
Then I decided to rewrite this to use the new I2C driver in <i2c_master.h> like so:
This code however works only at 100kHz, not at 400kHz. At 400kHz the line:
i2c_master_transmit(device_handle, (uint8_t []){ 0x00, 0x01 }, 2, -1);
fails withESP_ERR_INVALID_STATE
and the logs show:Thoughts on why the new i2c driver doesn't work at 400kHz while the old one does?
The text was updated successfully, but these errors were encountered: