2
\$\begingroup\$

I want to know if I need to use a bi-directional level converter to send data from an ESP32 to a 5V display, using serial communications (TX and RX).

I understand the serial communication is uni-directional over the level shifter would need to be bi-directional since the TX from ESP32 to the display's RX is going from 3.3V to 5V, and then the TX pin from the display to the ESP32's RX pin is going from 5V to 3.3V, hence the bi-directional level shifter.

I was therefore thinking of using the enter image description here

from Sparkfun. It is correct that I would need a bi-directional level shifter and if the one below will suffice for a baud rate o 9600.

\$\endgroup\$
5
  • \$\begingroup\$ Are RX and TX the same common pin at each end? \$\endgroup\$
    – Andy aka
    Oct 14, 2021 at 9:28
  • \$\begingroup\$ @Andyaka what do you mean? \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 9:30
  • \$\begingroup\$ A bidirectional level shifter is required when a single pin can operate as TX then switch to RX then back and forth. Does your circuit need to implement that? \$\endgroup\$
    – Andy aka
    Oct 14, 2021 at 10:44
  • \$\begingroup\$ @Andyaka arrghhh no the TX will always be TX and Rx will always be RX for each device \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 12:39
  • \$\begingroup\$ Then you don't need a bidirectional level shifter. \$\endgroup\$
    – Andy aka
    Oct 14, 2021 at 12:45

3 Answers 3

3
\$\begingroup\$

After reading the blurb on the SparkFun board you linked to, it will be fine for the job, as long as the signals are quite slow, up to a few hundred kilohertz at best. That translator relies on pull-up resistors, which are not really suitable for faster signals. 9600 baud will be OK. This is how you'd wire it up:

schematic

simulate this circuit – Schematic created using CircuitLab

You are not correct when you state that you need a bi-directional level shifter, because the signals are not bi-directional. What you have is two uni-directional signals.

Read up on I2C for an example of bi-directional signalling, where device pins can act as both inputs and outputs. In your application, I assume TX is always an output, and RX is always an input.

In your application you could get away with two unidirectional translators, one to shift a 5V output down to 3.3V suitable for the other device's input, and the other to go from 3.3V output to a 5V signal for the other device's input.

That might look like this:

schematic

simulate this circuit

Translator U1 has an input expecting 0V or 5V, but outputs only a 0V or 3.3V signal. U2 should take a 3.3V level input and output a 5V version.

There are many ICs you can use to shift between signal levels. Check out the 74LVC125, CD4504 for example. If you wish to convert 3.3V output signals to 5V, any 74HCTxx gate will do the trick, like the 74HCT08 or 74HCT32. You could even invert, using a 74HCT04 or 74HCT00.

The main advantages of using dedicated ICs like these to perform level shifting, rather than a MOSFET with pull-up resistors (like the SparkFun board), are speed and power. They'll be able to switch much faster, at several megahertz, with sharper transistions, while being able to sink and source much more current.

Up to a few tens or hundreds of kilohertz, the SparkFun board will work just fine, and you only need one unit.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks Simon. I will rather just buy the BSS138 FETs and make my own, and it will cost less than to buy those ICs. In fact I will still inlcude those ICs in my PCB as a backup incase those FETs run out. \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 14:14
  • \$\begingroup\$ So I cannot just use one IC for this. SInce one IC is been used for 3.3V to 5V and then another IC is been for 5V to 3.3V. Gees thats alot of space for these ICs needed on the PCB and alot of wasted pins on the ICs. \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 14:34
  • \$\begingroup\$ @Joey, yeah, that's the problem with ICs in this role. If you had an 8-bit wide bus that you needed to translate, then you could justify using ICs, but in this case it's a lot smaller and easier to go with the SparkFun module, or discrete MOSFETs/resistors. Having said that, I'm sure there's a bidirectional translator out there suitable for your application, but I can't think of one off the top of my head. \$\endgroup\$ Oct 14, 2021 at 14:40
  • \$\begingroup\$ is there any reason why I cannot connect some LEDs on the LV side of the module to see when info is going or coming in? \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 18:28
2
\$\begingroup\$

No you don't need a bi-directional level shifter for two unidirectional signals. For 9600 bps UART comms that level shifter might work but in theory that's not a correct kind of level shifter. It is mainly meant for level shifting I2C bus.

\$\endgroup\$
4
  • \$\begingroup\$ what level shifter would be best \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 12:37
  • \$\begingroup\$ @Joey I don't know what your specs are for "best", and that would depend on many factors, including if the 5V display 5V data input is logic level compatible with 3.3V output so then best is a direct connection with wire. \$\endgroup\$
    – Justme
    Oct 14, 2021 at 13:12
  • \$\begingroup\$ The display will not function with 3.3V. I have tested that. And the tx line of the display goes from 0 to approx 5V so this will damge the RX pin of the esp32 for sure. Will a simple resistor divder work for this baud rate of 9600 or do I need to use someting else? \$\endgroup\$
    – JoeyB
    Oct 14, 2021 at 13:55
  • \$\begingroup\$ @Joey note, that "you don't need" in the answer does not mean "you can't use it". As Justme pointed out, this shifter should work OK at 9600, and it is cheap. Also, after you made sure it works for you, you can duplicate 2 channels of it on your own pcb for a compact solution with only 2 fets and 4 resistors. A lot of Adafruit boards are made exactly like that. \$\endgroup\$
    – Maple
    Oct 14, 2021 at 21:30
1
\$\begingroup\$

Just to supplement already provided correct answers, here are some options for you to consider:

  • You can replicate 2 channels of Sparkfun shifter on your own board, using 2 FETs and 4 resistors;

  • You can use dual FET chip to reduce number of components to 5, as it is done for example here;

  • You can further reduce footprint by using resistor array, for a total of 2 components.

  • Finally, you can go as low as a single component solution with dedicated 2-bit voltage translators like TXS0102 or TXB0102 (at your speeds you probably will be OK without bypass and OE control components). Can't get any simpler than this.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks but the TXB0102, the price is by far the most expensive.... :) \$\endgroup\$
    – JoeyB
    Oct 15, 2021 at 7:32
  • 1
    \$\begingroup\$ $1.10 is expensive? It is half of the Sparkfun board price \$\endgroup\$
    – Maple
    Oct 15, 2021 at 17:03
  • \$\begingroup\$ Not the Sparkfun board. The BSS138 fet is cheaper than the TXS IC \$\endgroup\$
    – JoeyB
    Oct 15, 2021 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.