Page 1 of 1

I2C Master and Slave with one ESP32 board

Posted: Mon Jun 26, 2023 8:46 am
by TomasCZ
Dear all, please, can I use one ESP32 board as Slave and Master for two I2C devices ? I sniff I2C data from an external I2C device (data for an OLED display) (SLAVE role) and would like just for testing for purposes to forward the data to an OLED display (MASTER role).
Thank you in advance.

Re: I2C Master and Slave with one ESP32 board

Posted: Mon Jun 26, 2023 11:02 am
by MicroController
ESP32 has 2 I2C controller (also referred to as port) [...]. A single I2C controller can operate as master or slave.
So yeah, it should be possible to have one controller as a slave and one as a master.

However, the ESP-I2C controllers are a bit "special" in what they can and cannot do in slave mode. Just auto-ack'ing and piping through all non-address bytes received should be feasible though.

Re: I2C Master and Slave with one ESP32 board

Posted: Tue Jun 27, 2023 4:07 pm
by nochkin
I would highly recommend to get a simple logic analyzer. I2C protocol is slow enough and you can get a cheap logic analyzer using 8 channels and 24MHz for like $10-$20 or so.
It will let you analyze I2C and even extract the exact data it's being sent over to your device.
It works completely transparent for both ends.

Re: I2C Master and Slave with one ESP32 board

Posted: Wed Jun 28, 2023 9:27 am
by TomasCZ
Yes, I use a copy of Salae logic analyzer to sniff the data from the I2C bus to comepare the data with the data sniffed by the ESP32 board. There is long way behind from Arduino Nano/UNO boards to ESP32 boards used with Arduino IDE to ESP-IDF where we finally got the same data as from the logic analyzer. No I am trying to check the reliability and playing with the buffer size and the portTICK_PERIOD_MS value.

Next step would be to test the data sniffed by the ESP board with the OLED display before we start to re-write everything made in IDE to ESP-IDF.