0

I need to interface my Raspberry Pi to my Uno hence I need to logic shift 5 V logic to 3.3 V. I will be sending data from the Uno to Pi and from the Pi to the Uno. My understanding is UART uses two pins one for sending and one for receiving. I have built myself one of these

enter image description here

I have only built myself one of these because I wasn't confident I can build it. I was expecting it would blow up or won't work. Anyway I was wondering do I need two of the above. Can I get anyway with just two of the following?

enter image description here

It would be very handy if I can because then I don't have to use more transistors and it's my understanding the first circuit is essentially the second circuit doubled up.

winny
  • 14,707
  • 6
  • 46
  • 66
Ageis
  • 3,353
  • 14
  • 45
  • 67
  • Please edit the question and use the built-in schematic editor. No need for copy-pasting CircuitLab images. CircuitLab is built into the question & answer editor. Just click on the schematic icon above the editor markdown input area when editing the question. – Kuba hasn't forgotten Monica Aug 31 '23 at 19:32

2 Answers2

1

The following is a rough-and-ready technique for experiments, and if you check all the voltages carefully, might be suitable for some designs.

One of the simplest methods, suitable for UARTs and short distances, is simply divide down the higher volts with a resistor divider. In this particular case, there's not any real noise margin, but for an experiment on the bench you can try this.

You have to check the exact details of the given systems

  • UNO Input: With a ATMega328P at 5V (such as in your Arduino Uno), the 3.3V signal is adequate as a high signal, where a the high threshold is 0.6 VCC, ie 3.0 V. The minimum promised logic high voltage, VOH min, on some models Raspberry is also 3.0V (ref), so it will work on the bench but you'd probably not want to do this in production. On some models it's only 2.4V, which may well not be enough to drive the ATMega.
  • Raspberry Pi Input In the other direction, you should check on your exact model in the Raspberry Pi datasheets, but on a 3.3V system you have assume that VIH max is no higher than VCC, ie 3.3V. For the RPi4 these values are unhelpfully given "TBD", though say "VDD_IO is the GPIO bank voltage which is tied to the on-board 3.3V supply." This appears to be the same as the CM4, where there is a voltage reference for GPIO, VGPIO_VREF, which can be 1.8V or 3.3V. On the CM4IO board, it's 3.3V, giving VIL min is 2.0V and max is VGPIO_VREF, ie VCC, ie 3.3V. See table 4 of CM4 datasheet, VGPIO_VREF is set by R5 on Fig. 5, of CM4IO datasheet. Some more values are given in the overview documentation.

schematic

simulate this circuit – Schematic created using CircuitLab

Calculating the resistors:
5 V * 33000 / (18000 + 33000) = 3.24V

ATMega328P

Note that the reset and crystal pins have different thresholds.

enter image description here
From ATMega328P datasheet

jonathanjo
  • 14,034
  • 3
  • 34
  • 66
  • How do you know if 3.3V is adequate on a 5V system? On some systems it might be. Especially in this case it isn't, as a 5V ATMega328P requires at least 0.7*VCC so 3.5V at 5V supply to read high. It goes the other way too; some 3.3V MCUs tolerate 5V but not Raspberry Pi. – Justme Aug 31 '23 at 20:42
  • @justme Are you sure? I checked datasheet (and added a reference to this answer), I see no 0.7 x Vcc except for the crystal. The later ATMega328PB has an 0.7 x Vcc for Vcc<2.4V and 0.6 x Vcc above; but the UNO of the question is a 5V 328P. If I've missed something I'll happily correct my answer. – jonathanjo Sep 01 '23 at 10:33
  • You also need to check the Voh(min) for the 3.3V system. This will likely be lower than 3.3V, and if it ends up being lower than Vih for the 5V system allowing some noise margin, not a good design choice. – Tom Carpenter Sep 01 '23 at 11:31
  • 1
    There are specifications for the RasPI IO pins listed here, part way down there is a table for "Voltage Specifications". That lists Voh can be as low as 3V for RPi2/RPi3 and 2.6V for RPi 4, which would be at (no noise margin) or below the Vih for the 5V atmega. Might work fine for a one-off, but I wouldn't trust it for anything important or in quantity. – Tom Carpenter Sep 01 '23 at 11:38
  • @TomCarpenter thanks very much for better ref, I've edited the answer to say it's a rough-and-ready one for the bench. – jonathanjo Sep 01 '23 at 12:08
0

Can I get anyway with just two of the following?

Note that the two sub-circuits in the first figure are different. You need one for 3-to-5V translation, another for 5-to-3V.

Since both the 3V and 5V output are driven all the time, there's no need for pull-ups. So only then do the two circuits become identical:

schematic

simulate this circuit – Schematic created using CircuitLab

  • I got the circuit from a different thread on here. It said the first circuit is bi-directional version of the second, is that not true? By bidirectional I assumed it meant 3.3V to 5V and 5v to 3.3V – Ageis Aug 31 '23 at 21:27
  • R1 probably not needed unless the inout signal is also driving a pulldown load – Jasen Слава Україні Sep 01 '23 at 06:16
  • @Ageis: With UART, which has two opposing unidirectional signals, you really do not want a bidirectional level translator. Those have a nasty habit of detecting some noise at their output and starting to drive the input. Instead, use a unidirectional translator appropriate to each signal direction. – Ben Voigt Sep 01 '23 at 15:40
  • Oh is that why I got random values when reading from the serial interface – Ageis Sep 01 '23 at 16:20