I2C timeout and ESP32 S3 version

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

I2C timeout and ESP32 S3 version

Postby RobMeades » Wed Feb 22, 2023 2:45 pm

Hi there: we've been running I2C stuff very happily on ESP32 for a while now. We've just switched to using ESP32S3 and find that the i2c_set_timeout() function is failing.

Checking, it seems that for a "normal" ESP32 chip the maximum I2C timeout value is 0xFFFFF x 80 MHz APB clock cycles (so about 13 milliseconds), whereas for an ESP32S3 the maximum value for I2C timeout is only 31 x 80 MHz APB clock cycles, so 0.38 nanoseconds.

Is that correct? It seems quite a dramatic change. We, maybe incorrectly, set the I2C timeout to 10 milliseconds, hoping that gives the device at the far end the maximum time to respond. I guess there's no way to achieve this with ESP32S3?

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: I2C timeout and ESP32 S3 version

Postby RobMeades » Sat Feb 25, 2023 8:16 am

Does anyone have any ideas on this? Must be someone else out there using I2C on an S3 and needing to set an I2C timeout value? How do you do that? Or maybe you don't and it "just works"? Any clues appreciated.

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: I2C timeout and ESP32 S3 version

Postby RobMeades » Wed May 17, 2023 2:02 pm

For the benefit of anyone who gets here, after a few days of conversation with an _extremely_ helpful and knowledgeable Espressif engineer, we figured out my misunderstanding, details here: https://github.com/espressif/esp-idf/issues/11397 but in summary the timeout value value passed ESP32 is a multiplier on the 80 MHz APB clock but on the ESP32S3 it is NO LONGER THAT SIMPLE, the value is instead a power of two times either the XTAL (40 MHz) or, if you have selected it, the RC network (17.5 MHz) clock period. So:

ESP32S3: timeout = 2^x * (1/40000000)

...which is how they can get away with having a 5-bit timeout register. The technical reference manual and ESP-IDF documentation don't really make this switcheroo clear, be warned!

Lalith
Posts: 2
Joined: Fri Jul 14, 2023 9:45 am

Re: I2C timeout and ESP32 S3 version

Postby Lalith » Wed Jul 19, 2023 5:07 am

Hi, Did you get your I2C timeout issue solved? using the i2C_set_timeout(),

I have been trying to get my communications working but facing similar issues you faced. I have been trying to communicate to a Sensirion Sensor, after reading the 1st data after reboot i have been getting Only TIMEOUT ERROR on the ESP32 S3. By any chance do you have any suggestions to solve this state?

Thanks in advance

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: I2C timeout and ESP32 S3 version

Postby RobMeades » Wed Jul 19, 2023 8:08 am

For me the issue was just that the value one passes to the i2c_set_timeout() function needs to be calculated differently for the ESP32x3 chips: it is no longer a simple millisecond value, it is 2^SCLK_period.

For example, if the 40 MHz crystal is chosen as SCLK then you have 2^(x * 25) ns, where x can be a maximum value of 22, so for instance the largest timeout value is 2^(22 * 25) ns = 104.9ms.

Who is online

Users browsing this forum: No registered users and 288 guests