EN

Logic level shifting

Compatibility between families, noise margins and how to connect 5 V to 3.3 V

The four thresholds

For an output and an input to understand each other it is not enough that they share the same supply: four voltages from their datasheets must be compared.

\[ NM_H = V_{OH} - V_{IH} \ge 0 \qquad NM_L = V_{IL} - V_{OL} \ge 0 \]

The noise margins \(NM_H\) and \(NM_L\) are the interference voltage the connection withstands without errors. Between VIL and VIH there is a forbidden zone where the input may read anything. There is also a fifth condition: the output voltage must not exceed the maximum the input accepts, usually its supply plus 0.3 V, unless it is 5 V tolerant.

Compatibility checker

Typical catalogue values with light load (JEDEC for the families, datasheets for the microcontrollers). With high output currents VOH drops and VOL rises: always check the datasheet of the actual parts.

Resistive divider (stepping 5 V down to 3.3 V)

It is the simplest method for a one-way signal going down in level: two resistors reduce a 5 V logic 1 to a little over 3 V. Its limit is speed, because the input capacitance charges through the equivalent resistance of the divider.

V
V
kΩ
V
V
pF
\[ V_{out} = V_{in}\,\frac{R_2}{R_1 + R_2} \qquad R_{th} = \frac{R_1 R_2}{R_1 + R_2} \qquad t_r \approx 2.2\,R_{th}\,C \]

For a reliable signal each half-period should last at least about three times the rise time; the calculator gives the maximum frequency with that rule. Resistors of a few kΩ are fine for UART and slow SPI; for SPI at several MHz the divider falls short and a buffer is better.

Shifting methods

MethodDirectionSpeedTypical use
Resistive dividerDown (5 → 3.3 V), one-wayLow to medium (depends on the resistors)UART RX, slow signals, sensor inputs
Series resistor (1 to 10 kΩ)Down, one-wayMediumOnly if the datasheet allows current through the protection diodes; not recommended
Direct connectionUp (3.3 → 5 V)HighWorks if the receiver has TTL inputs (VIH = 2 V): 74HCT, 74ACT, many modules
N-channel MOSFET with two pull-ups (BSS138, 2N7002)Bidirectional, open-drain outputsUp to a few hundred kHzI²C, 1-Wire, SMBus
Buffer with 5 V tolerant inputs (74LVC, 74LVC1G)Down, one-wayVery high (tens of MHz)SPI, clocks, fast buses
74HCT/74AHCT buffer powered at 5 VUp, one-wayHighWS2812 LED strips from a 3.3 V microcontroller
Dual-supply translator (74LVC245, SN74LVC8T245)Bidirectional with direction pinVery highParallel and data buses
Auto-direction translator (TXB0108, TXS0108E)Bidirectional without direction pinHighTXB for push-pull outputs; TXS for open drain and I²C

The MOSFET level shifter

This is the circuit on cheap "level shifter" modules. An N-channel MOSFET has its gate at 3.3 V, its source on the 3.3 V side and its drain on the 5 V side, and each side has its own pull-up. It works in both directions:

It needs a MOSFET with a threshold voltage well below the low supply (BSS138: 0.8 to 1.5 V) and is meant for open-drain outputs. It also works with push-pull outputs, but the rising edge depends only on the pull-up, so it is slow.

Rules of thumb

Related: pull-up resistors and I²C bus, transistor as a switch, optocouplers and Ohm's law.