when you say that TXS0108E is perfect for I2C , do you know how could I fix my issue to make it work ? this issue is annoying me and I can't figure out any option.
My sincere apologies: I absolutely forgot about that part! (Me fail, once again.)
Did you forget the pull-up resistors?
You see, I²C is an
open collector bus, which is just a name for a bus where all devices on the bus can only pull the signal lines to ground. They cannot actually push or pull the signal line to any specific positive voltage. To ensure the signal lines are high, we need to use specific resistors.
Note that only one resistor is needed per signal, i.e. one resistor between SDA and VCC, and one resistor between SCL and VCC. You do not need one resistor per signal per device; just one per signal line. (If you were using the 3Mbit/s or 5Mbit/s data rates, then it might be useful to use one resistor at each end of each signal line, twice the resistance of a single resistor, but those speeds are extremely rare in Arduino land.)
The lower the resistor value, the more current runs in the signal wires (when pulled to ground). These resistors vary from 1k to 10k, with 2.2k most common. The smaller the current, the closer to ground the device can pull the signal line.
When using bidirectional translators like TXS0108E for I²C, it is also important to realize that the signal line on each side of the TXS0108E requires their own pull-ups; the pull-up does not "pass through" the TXS0108E.
To connect the MPU6050 to RPi, you need:
- Wire from RPi GND to MPU6050 GND
- Wire from RPi +3.3V to MPU6050 VCC
- Wire from RPi SDA to MPU6050 SDA
- Wire from RPi SCL to MPU6050 SCL
- 2.2k resistor between SDA and +3.3V
- 2.2k resistor between SCL and +3.3V
Wire this up, and test.
To connect the ADC to RPi, use:
- Wire from RPi GND to TXS0108E GND
- Wire from RPi +3.3V to TXS0108E VCCA
- Wire from RPi +5V to TXS0108E VCCB
- Wire from RPi SDA to TXS0108E A3
- Wire from RPi SCL to TXS0108E A4
- Wire from RPi GND (or TXS0108E GND) to ADC GND
- Wire from RPi +5V (or TXS0108E VCCB) to ADC VCC
- Wire from TXS0108E B3 to ADC SDA
- Wire from TXS0108E B4 to ADC SCL
- 2.2k resistor between RPi SDA (or TXS0108E A3) and +3.3V. (This is the same SDA resistor as in the previous test.)
- 2.2k resistor between RPi SCL (or TXS0108E A4) and +3.3V. (This is the same SCL resistor as in the previous test.)
- 2.2k resistor between ADC SDA (or TXS0108E B3) to +5V.
- 2.2k resistor between ADC SCL (or TXS0108E B4) to +5V.
I recommend you try the above separately first. When both work separately, you can combine them. Note that when combining, you only need four resistors, not six.
Note that TXS0108E cannot supply much current on its outputs. If you want to switch power to peripherals on and off, you need something called a "high-side switch". For +3.3V, a single P-channel MOSFET suffices (I like DMP3099L for Arduino peripherals); for higher voltages, you need a P-channel MOSFET and either an N-channel MOSFET or NPN transistor. You'll also need a current-limiting resistor (for the GPIO pin –– MOSFET gates behave like capacitors, so when changing state, may draw uncomfortably much current from the GPIO pin, which the resistor limits to safe values, only slowing the switching action a tiny bit), and a pull-up/down resistor to set the state of the "high-side switch" when the GPIO pin is an input.
I have found other modules on internet that use BSS138 and few resistors to make the logic conversion.
These have their own problems, especially switching speed. I consider them in the same class as other bidirectional voltage level translators.
In general, I do like BSS138 (although I tend to use NX138AK instead, which is slightly faster switching, but otherwise almost identical, in three-pin SOT23 footprint) for my 2.5V to 12V signal-related N-channel MOSFET needs.
I'm only a hobbyist myself, mostly using microcontrollers with native USB interfaces (like Teensy) to add user interfaces and other stuff to Linux-based SBCs and appliances like routers and TV boxes. I don't like the hardware compromises in USB implementations on the Raspberry Pis, and I don't like how the Foundation does not directly interface to the open source projects they rely on and insist hiding anything Linux or Open Source by their own naming schemes.
It is exactly because of a lack of existing voltage translation modules for UART and SPI that I created my own. (The very first one I did, was one using two 74LVC1T46 IC's in SOT23 footprint, to interface a Teensy LC to the 1.8V UART on Odroid HC1.) After that, I noticed that when connecting separately-powered devices (like my desktop computer with a properly grounded supply) to other devices using wall warts (we have unpolarized "Schuko" sockets here; no live and mains, both are live, so ungrounded supplies 0V/GND level floats somewhere not even close to true ground), I was getting ground current loops (because their GNDs were at different potentials), and started using isolators too. (I particularly like TI ISO6721, which is very similar to TI TXU0102, allowing different supply voltages on each side, but
also isolates the two GNDs.) Note, however, that I've been
ridiculed for that here, so I might be doing things wrong. I don't believe so, of course, based on the results I get.
The Schmitt trigger inputs on the TXU0
n0
m inputs also mean that when the GPIO pin they are connected to is floating (an input, during bootup when it is not yet configured as an UART pin), no excess current will flow. When the pin floats at an intermediate voltage (for 3.3V CMOS logic like RPi 4 uses, 0.8V and below is "low", and 2.0V and above is "high"; so between 0.8V and 2.0V in this case), and it is connected to the gate or base of a transistor, the transistor may be in its linear region, and instead of either fully conducting or non-conducting, acts like a resistor (with its resistance depending on the voltage on the gate; as described by its gate-source voltage to on-state resistance curve, if given, in the datasheet). That means it can waste power and generate excess heat. The Schmitt trigger inputs avoid all that, even if their output is used to control a transistor gate or base.