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?
I2C doesn't work properly if reconfigure the gpios used
I2C doesn't work properly if reconfigure the gpios used
- Attachments
-
- 1.JPG (96.89 KiB) Viewed 5932 times
Re: I2C doesn't work properly if reconfigure the gpios used
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.
I2C driver provides this to configure the new GPIOs:
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);
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);
Re: I2C doesn't work properly if reconfigure the gpios used
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?
Now, I am wondering why Espressif didn't consider disconnecting the previously used Gpios upon the new pair of gpio assigning?
Re: I2C doesn't work properly if reconfigure the gpios used
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
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
Re: I2C doesn't work properly if reconfigure the gpios used
Correction:
i2c_param_config()
Burtrum
i2c_param_config()
Burtrum
Re: I2C doesn't work properly if reconfigure the gpios used
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: No registered users and 100 guests