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
Parallel dynamic I2C PIN switch for I2C Multiplexing
-
- Posts: 4
- Joined: Wed Oct 11, 2023 9:45 pm
Parallel dynamic I2C PIN switch for I2C Multiplexing
Last edited by BastelBaus on Thu Oct 12, 2023 4:45 am, edited 1 time in total.
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Parallel dynamic I2C PIN switch for I2C Multiplexing
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.
-
- Posts: 4
- Joined: Wed Oct 11, 2023 9:45 pm
Re: Parallel dynamic I2C PIN switch for I2C Multiplexing
That’s promising, thanks for the fast reply. I will give it a try!
-
- Posts: 4
- Joined: Wed Oct 11, 2023 9:45 pm
Re: Parallel dynamic I2C PIN switch for I2C Multiplexing
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 ...
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 ...
-
- Posts: 4
- Joined: Wed Oct 11, 2023 9:45 pm
Re: Parallel dynamic I2C PIN switch for I2C Multiplexing
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
>> [ 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
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Parallel dynamic I2C PIN switch for I2C Multiplexing
Sorry, I have no experience with the Arduino I2C implementation. Could be that it's not re-entrant indeed, I don't know.
Who is online
Users browsing this forum: No registered users and 87 guests