2025-01-26 8:52 AM - last edited on 2025-01-29 8:58 AM by mƎALLEm
I tried creating I2C connection between my stm32 board and esp32. I assume it is not working because of my code, due to the wiring being so simple in I2C communication, the pull up resistor is connected externally. Do you guys see any mistake in my code that could make my I2C to not work? I cannot figure out why it would not work.
2025-11-10 8:50 AM
Have a look at my post. it may be helpful.
ESP32 AND STM32 I2C INTERFACE
2025-11-10 9:15 AM
@tantheman did you mean to give a link?
https://community.st.com/t5/others-stm32-mcus-related/esp32-and-stm32-i2c-interface/td-p/854859
2025-11-10 9:20 AM
yes meant to give the link but was facing some errors .... being new to the site
2025-11-10 9:36 AM
Seems in Arduino you miss order , right is
bool Wire.begin(uint8_t addr, int sdaPin, int sclPin, uint32_t frequency);
2025-11-10 10:16 AM
It looks like the confusion here mostly comes from how the STM32 HAL handles 7-bit I2C addresses. A few key points:
Address Shifting – STM32 HAL expects the 7-bit slave address shifted left by 1. The LSB is reserved for the R/W bit. So if your ESP32 slave address is 0x08, you should pass 0x08 << 1 to the HAL functions.
Pull-up Resistors – Make sure both SDA and SCL lines have pull-up resistors. Without them, communication can be unstable, especially at higher speeds.
Check Master vs Slave – Confirm which device is the master and which is the slave. Test each side with a known-working device first before connecting STM32 ↔ ESP32.
Debugging – If possible, use an oscilloscope or logic analyzer to check the I2C lines. Look for proper clock and data transitions. Noise or missing ACKs are common culprits.
HAL vs Arduino Wire – Note that STM32 HAL requires the address shifted left, while Arduino Wire library uses unshifted 7-bit addresses. That difference often causes confusion when connecting STM32 to Arduino/ESP devices.
Start Simple – Use a minimal setup first: one master, one slave, simple read/write commands, then scale up to multiple devices.
Following these steps usually resolves most STM32 ↔ ESP32 I2C issues.