define esp32 as master device using new i2c_master.c functions

lubusax
Posts: 2
Joined: Mon Apr 15, 2024 6:04 pm

define esp32 as master device using new i2c_master.c functions

Postby lubusax » Mon Apr 15, 2024 6:19 pm

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?

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Tue Apr 16, 2024 10:07 pm

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

lubusax
Posts: 2
Joined: Mon Apr 15, 2024 6:04 pm

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

Postby lubusax » Wed Apr 17, 2024 2:24 pm

Thank you.
It seems to work.
:D

Who is online

Users browsing this forum: No registered users and 105 guests