I2C Communication Problem Between ESP32 and STM8

I have a ESP32-WROVER-E(master) and a STM8S003F3(slave). I set up I2C communication between them. I set STM8S I2C output clock frequency to 100KHz. ESP32 I2C clock frequency is the default(100KHz). But it doesn’t work. I used 10K, 4.7K and 1K pull-up resistors but nothing changed. If I set the ESP32 I2C clock frequency to 62.5KHz or lower, it works. I used Arduino Mega instead of ESP32. It worked without the need to adjust the I2C clock frequency. What would be the reason? Why ESP32 not working at 100KHz? What’s the difference between ESP32 and Arduino Mega?
Thank you in advance

The ESP32 might be too fast for the STM8. The Arduino Mega is slower with its overhead, and that creates small pauses on the I2C bus.
The Master always provides the clock pulses in all situations. You can set the Slave to any clock speed, it does not matter.

A processor running as I2C Slave might need some time.
Can you try this:

Wire.beginTransmission();
Wire.write( ...
Wire.endTransmission();

delay(1);

Wire.requestFrom( ...

Thank you for reply, Koepel. I tried but it didn't work. Do you have any other solutions?

No, sorry. I have no clue :frowning:
Can you read the next things ? Which one stands out ?

Timing

They are both processors and there might be software/hardware timing differences. Perhaps the STM8 is too fast and a glitch by the ESP32 is seen as a pulse. Some boards produce glitches on the I2C bus, and no one cares when they are in a location that does no harm.
The ATmega2560 microcontroller (on the Mega board) has a slew-rate limiter for the outgoing signals and a filter for the incoming signals of the I2C bus (inside the chip). That can make a difference.

I think the ESP32 supports clock pulse stretching to about 10ms if I remember it correctly.
The Mega fully supports clock pulse stretching and the STM8 uses that.
Making the ESP32 work by lowering the clock does not indicate a problem with clock pulse stretching.

You could try to capture the signals with a logic analyzer.
I'm very fond of the 30 dollar LHT00SU1 with sigrok/PulseView.

Voltage levels

The ESP32 runs at 3.3V, and its pins are not 5V tolerant. It has therefor a 3.3V I2C bus. You should not pull its SDA and SCL to 5V with a pullup resistor. You may not connect it with a 5V I2C bus without level shifter.
There is more on this page that I wrote: How to make a reliable I2C bus.

Is your STM8S003F3 running at 5V or 3.3V ?
If it is running at 5V, then there is no voltage mismatch on the I2C bus when the Mega is used.
The Arduino Mega 2560 has onboard 10k pullup resistors to 5V.

Cable

Do you use a cable ? or a short flat ribbon cable with SDA next to SCL ?

Ground

Are the GNDs connected ?

Thank you for reply, Koepel. STM8S runs at 3.3V and GNDs are connected. Logic analyzer view of I2C communication at 100 KHz:

That is a single pulse, that is not I2C communication :confused:
When the I2C bus is idle, both SDA and SCL should be high.
I don't know what is going on, but this is not I2C.

Time to post code in code tags.

I opened an issue on GitHub. [I2C communication problem between ESP32 and STM8 · Issue #4928 · espressif/arduino-esp32 · GitHub]

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.