I2C doesn't work properly if reconfigure the gpios used

ukrsms
Posts: 24
Joined: Tue Aug 20, 2019 11:30 am

I2C doesn't work properly if reconfigure the gpios used

Postby ukrsms » Fri Aug 06, 2021 11:22 am

I am trying to communicate with two devices having the same I2C address, so I connected them to different gpio pairs (18,19 and 22,23).

In my code, I start the driver (i2c_driver_install), configure it (i2c_param_config) with the first pair of gpios and write 5 bytes to the bus (to the first chip).
After this I reconfigure the driver for the second pair of gpios to be used and write 5 bytes (to the second chip).
Then, I repeatedly read 5 bytes from each chip reconfiguring the driver for the right gpios.
However, I found that after the first time I reconfigure the gpios used by the I2C driver, the data appears on both pairs of gpio - previous and new. Here is the diagram taken from both gpio pairs for a reference
Could anyone tell me whether is it possible to switch pins used by I2C driver on-the-fly not to disturb other pins?
Attachments
1.JPG
1.JPG (96.89 KiB) Viewed 6067 times

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: I2C doesn't work properly if reconfigure the gpios used

Postby boarchuz » Fri Aug 06, 2021 12:00 pm

According to https://github.com/espressif/esp-idf/bl ... #L228-L242, 0x100 is the magic number to disconnect the I2C signal from the previous pins.
eg.

Code: Select all

// Disconnect previous
gpio_matrix_in(GPIO_NUM_18, 0x100, 0, 0);
gpio_matrix_out(GPIO_NUM_18, 0x100, 0, 0);
gpio_matrix_in(GPIO_NUM_19, 0x100, 0, 0);
gpio_matrix_out(GPIO_NUM_19, 0x100, 0, 0);
I2C driver provides this to configure the new GPIOs:

Code: Select all

i2c_set_pin(i2c_port_t i2c_num, int sda_io_num, int scl_io_num, bool sda_pullup_en, bool scl_pullup_en, i2c_mode_t mode);

ukrsms
Posts: 24
Joined: Tue Aug 20, 2019 11:30 am

Re: I2C doesn't work properly if reconfigure the gpios used

Postby ukrsms » Fri Aug 06, 2021 12:14 pm

Thank you, boarchuz, your answer really help me. Currently, I can access both I2C chips correctly!
Now, I am wondering why Espressif didn't consider disconnecting the previously used Gpios upon the new pair of gpio assigning?

burtrum
Posts: 20
Joined: Mon Dec 28, 2015 1:34 pm

Re: I2C doesn't work properly if reconfigure the gpios used

Postby burtrum » Sun Aug 08, 2021 4:12 pm

Thank you for asking this I2C pin question, I should have asked it a month ago.

I am preparing to release a ESP32 I2C task-safe interface with unlimited I2C buses, constrained only by available GPIO. But i2c_set_pin() didn’t work so I used i2c_config() to attach to pins and gpio_config() to release pins which worked great.

Named “sys_i2c”, it started as just a task-safe effort, but a I soon added the GPIO matrix, mutexes, and a simple configuration table for easy GPIO assignment.

I’ll upload my current code next week as is, and test with this new info.

Look for it very soon.

Burtrum

burtrum
Posts: 20
Joined: Mon Dec 28, 2015 1:34 pm

Re: I2C doesn't work properly if reconfigure the gpios used

Postby burtrum » Sun Aug 08, 2021 4:49 pm

Correction:
i2c_param_config()

Burtrum

dssman
Posts: 17
Joined: Thu May 26, 2022 4:37 pm

Re: I2C doesn't work properly if reconfigure the gpios used

Postby dssman » Mon Jun 06, 2022 6:40 pm

ukrsms wrote:
Fri Aug 06, 2021 12:14 pm
Thank you, boarchuz, your answer really help me. Currently, I can access both I2C chips correctly!
Now, I am wondering why Espressif didn't consider disconnecting the previously used Gpios upon the new pair of gpio assigning?
Hi ukrsms.
May I ask how you solved your problem?
I met the same question and I tried to use Disconnect previous lines to cut the previous used pin 21/22, and signed new I2C pin: 14/15, not work.
Thanks
Adam

Who is online

Users browsing this forum: jesper and 141 guests