Page 1 of 1

define esp32 as master device using new i2c_master.c functions

Posted: Mon Apr 15, 2024 6:19 pm
by lubusax
Hello,

I would like to use the ESP32 as a I2C master device using Bus 0.
I have no issues while using the "old" i2c.c functions (I can make it work with no problems).
But the "old" i2c functions are deprecated.

So I looked into the "new" way of doing things (IDF v5.2.1). But I can not make it work.

As I understand from https://docs.espressif.com/projects/esp ... 2%20master
one should:
1. get a new bus handle using i2c_new_master_bus
2. define a new master device handle for the ESP32 (?) , is this correct? Using i2c_master_bus_add_device ?
Or is there anopther way to configure the Bus 0 with the ESP32 I2C controller working as a master?

So, I do not know how to configure the new Bus to be used by the ESP32 with the ESP32 I2C controller being the master of the Bus.

What I am missing/ not understanding? Can someone please help me?

Re: define esp32 as master device using new i2c_master.c functions

Posted: Tue Apr 16, 2024 10:07 pm
by MicroController
1) init the I2C controller/bus you want via i2c_new_master_bus()
2) for every slave device you want to talk to, add a device to the 'bus' (i2c_master_bus_add_device())
3) pass the slave device's 'handle' (i2c_master_dev_handle_t) to i2c_master_transmit()/i2c_master_transmit_receive()/... to communicate with this slave.

See e.g. https://github.com/espressif/esp-idf/bl ... prom.c#L37

Re: define esp32 as master device using new i2c_master.c functions

Posted: Wed Apr 17, 2024 2:24 pm
by lubusax
Thank you.
It seems to work.
:D