Page 1 of 1

i2c clock speed reduction when failing to communicate to a slave

Posted: Thu Jun 01, 2023 12:24 pm
by dami98
Hi all,
i am facing a problem when my ESP32-S2 fails to communicate to an i2c slave, the problem is better described in the following.

At start the i2c port is set to work with a clock frequency of 400 MHz and it works fine until i disconnect the i2c slave. When i connect it again, the esp32s2 is able to start communicating with it again but at a much lower clock speed (around 5 kHz). Reading the values of configured with the function i2c_get_period(), i can notice that the returned value is not changed, however the clock frequency changes so it should be something related to the hardware i think.

Any one can explain this behaviour?

Thanks.

Re: i2c clock speed reduction when failing to communicate to a slave

Posted: Mon Jun 19, 2023 10:19 am
by dami98
Doing some more in depth research i noticed the following:
if f_scl=400kHz at beginning, f_scl=5khz at the end;
if f_scl=100kHz at the beginning, f_scl=1,25kHz at the end;
the ratio is 80 which is the same ratio as APB_CLK / REF_TICK
This means that when esp32s2 fails to communicate to the sensor, in some way the clock source for the i2c is switched from APB_CLK to REF_TICK.

Re: i2c clock speed reduction when failing to communicate to a slave

Posted: Mon Jun 19, 2023 12:34 pm
by maldus
I too have stumbled upon this behaviour, though I didn't diagnose it in such detail.

If an I2C device stops answering for a while the ESP32 module is not always able to it pick up again. I am trying the solution described here https://esp32.com/viewtopic.php?f=14&t=3152&p=14817 (i.e. reset the peripheral with periph_module_disable and periph_module_enable) but I can't say for sure whether it's working yet.

Still, it appears to be a long standing issue, it would be nice to know if there is a definitive fix.

Re: i2c clock speed reduction when failing to communicate to a slave

Posted: Thu Nov 09, 2023 7:15 pm
by timc100
I too have had this problem and I reported it at the Espressif Github page as a bug, issue 8480, see
https://github.com/espressif/arduino-esp32/issues/8480

I didn't find this page though, until earlier today. Like those on this forum, the problem has been identified as impacting ESP32-S2, but not ESP32-S3 or older boards.

The same clock rate change from 400KHz to 5KHz was also noted and it only happens if the target device is not present on the bus.
I have found a work-around for it which is to set the clock rate to something else, then change it back to the desired speed, then make the I2C transaction on the bus.

The problem remains in the Alpha for v3.0.0 of the framework expected to be released around the end of the year. This version has a different bug that impacts I2C comms. 1.6MHz - 1.7MHz clock rates are generated when a 400KHz rate is requested. this has been raised as a separate defect 8855, see https://github.com/espressif/arduino-esp32/issues/8855