Page 1 of 1

Parallel dynamic I2C PIN switch for I2C Multiplexing

Posted: Wed Oct 11, 2023 9:55 pm
by BastelBaus
Dear community,

I am new here and not sure if I am right here. I have 3 identical I2C slaves with the same address, want to avoid bit banging and an extra I2C multiplexing. I was wandering If I could connect my slaves to different pins and just switch the IO_MUX of teh ESP32S to the PINS of device I want to address. Checking the function "i2c_set_pin" within [1] looked like this could work. Of course I have to manage initialization of both connected devices seperately and switch only between communications. Do you think this could be a feasible way ?
Wouldn't this be a concept to avoid I2C multiplexers (at the cost of using more ESP32 pins for some applicatios by adding suich a generic feature? I checked teh runtime ending and re-starting a complete Wire interface whcih took about half a millisecond and would be too much.

Any feedback welcome with hints or reasons why such a concept will not work at all.

BR
BastelBaus

[1] https://github.com/espressif/esp-idf/bl ... /i2c/i2c.c

Re: Parallel dynamic I2C PIN switch for I2C Multiplexing

Posted: Thu Oct 12, 2023 1:44 am
by ESP_Sprite
You probably could. Note that you may want to re-initialize the GPIOs you switched away from as normal GPIOs, otherwise the I2C signals may be sent to (but not read from) both pairs of pins.

Re: Parallel dynamic I2C PIN switch for I2C Multiplexing

Posted: Thu Oct 12, 2023 4:44 am
by BastelBaus
That’s promising, thanks for the fast reply. I will give it a try!

Re: Parallel dynamic I2C PIN switch for I2C Multiplexing

Posted: Thu Oct 12, 2023 10:00 pm
by BastelBaus
I really works like charm ! Please find my short proof of concept: https://hackaday.io/page/21183-hacking- ... lexing-i2c. Thanks for your good advice, this was the reason why it did not work the first time :-).

Do you see any chances to create out of this a real feature within the ESP libraries ? I mean I sawe a lot of the code and handling of exception, so I don't believe my hack will work really reliable and in all cases. But maybe it could be made to a real feature ?

BR,
BastelBaus


P.S.: Somehowe the first post vanished, I tried to add a notification flag but maybe messed up with something ...

Re: Parallel dynamic I2C PIN switch for I2C Multiplexing

Posted: Thu Oct 26, 2023 9:18 pm
by BastelBaus
After adding WiFi to my code, I get quite soon after some accesses this error:
>> [ 44354][E][Wire.cpp:513] requestFrom(): i2cRead returned Error -1
I assume this has to to with the threading. Don't switching the pins does work perfekt. Any idea how to debug ?

BR
BastelBaus

Re: Parallel dynamic I2C PIN switch for I2C Multiplexing

Posted: Fri Oct 27, 2023 2:59 am
by ESP_Sprite
Sorry, I have no experience with the Arduino I2C implementation. Could be that it's not re-entrant indeed, I don't know.