Chapters

20 Logic Level and Level Shifting Contracts

electronics-controller-design
logic-levels
gpio
level-shifting

20.1 Start Simple

Check Both Sides of One Digital Wire

Picture a 3.3 V controller reading a 5 V sensor board. The wire may carry sensible bits on the bench while still stressing the input or missing a reliable high level. The first safe move is to compare what one side guarantees with what the other side accepts.

GPIO means general-purpose input/output, a pin used for a direct digital signal. I2C means Inter-Integrated Circuit, a shared two-wire link for nearby parts. A microcontroller means a small computer chip that reads inputs and controls outputs.

Record supply rails, guaranteed high and low outputs, receiver thresholds, absolute limits, and power state on both boards. Test low, high, slow edges, one side unpowered, and restart. Reject a connection that only works by chance.

This runway does not prove that one level shifter fits every signal speed or bus. The deeper sections cover noise margin, dividers, buffers, open-drain links, active translators, rise time, clamps, and back-power risk.

Imagine a 3.3 V microcontroller connected to a 5 V sensor board. A wire that looks like a signal can still violate input thresholds, noise margin, or absolute-maximum ratings. Start by writing the HIGH and LOW voltages for both sides, then choose whether the connection can be direct, divided, buffered, or level shifted.

20.2 Learning Objectives

After this page, you should be able to:

  • Compare driver output guarantees with receiver input thresholds for a digital interface.
  • Calculate HIGH noise margin from VOH and VIH and explain why margin matters.
  • Decide when 3.3 V to 5 V or 5 V to 3.3 V links need level shifting.
  • Choose between resistor dividers, active translators, open-drain pull-ups, and MOSFET bus shifters.
  • Check absolute-maximum voltage, clamp-current, rise-time, and back-powering risks before connecting boards.

20.3 Why Electronics Tools Come First

Electronics Concepts and Calculators introduces GPIO limits, signal-versus-power separation, current limiting, switching components, and protection habits. This page turns those habits into an interface contract: a digital link must meet threshold math and must not exceed any pin’s survivability limits.

Use it when a 3.3 V microcontroller talks to a 5 V sensor, a divider is proposed on a fast signal, an I2C bus crosses voltage domains, a powered module can drive an unpowered board, or a datasheet threshold must replace a guess about compatible logic levels.

The mathematical gist. In the standard BSS138 shifter, the gate is tied to the 3.3 V rail and the source faces the 3.3 V bus. Pulling that side low therefore gives 3.30 V of gate-to-source drive. With a 4.70 kohm high-side pull-up and an illustrative 50 ohm on-resistance, the 5 V node sits only 53.2 mV above ground—3.55% of its 1.50 V LOW threshold. In the other direction, the body diode begins the hand-off when the high-side drain falls below about 2.65 V; the low-side pull-up asks for 0.702 mA.

Math Bridge · guided foundationsHow does one MOSFET pull a bus low in both directions?Let Eddie connect gate drive, body-diode hand-off, on-resistance, pull-up current, and logic margin.

20.4 Overview: Four Numbers Define a Logic Interface

Two chips talk digitally only if they agree on what voltages mean 0 and 1. Every logic interface is governed by four numbers: what a driver outputs and what a receiver requires.

When two devices use different supply rails, a shared word such as HIGH is not yet an electrical contract. Inspect Figure 20.1 to identify the two voltage domains and the translator boundary before checking the four guaranteed output and input levels.

Bidirectional voltage level shifter connecting a 3.3 volt logic domain to a 5 volt logic domain with VCCA, VCCB, ground, auto-direction channels, and common I2C, SPI, and GPIO uses.
Figure 20.1: Bidirectional level shifter connecting 3.3 V and 5 V logic domains.

The left side of Figure 20.1 is the 3.3V DOMAIN, powered through VCCA and connected on channels A1–A3; the right is the 5V DOMAIN, powered through VCCB and exposed on B1–B3. The central TXS0108E marks the translation boundary, while ↔ AUTO DIR shows that signals may travel either way. That topology does not by itself prove compatibility: the stated voltage range and speed are device capabilities, and the interface review must still compare VOHV_{OH} with VIHV_{IH}, VOLV_{OL} with VILV_{IL}, direction behaviour, and absolute-maximum limits for the chosen bus.

VOH / VOL

The driver's guaranteed output: at least VOH for a HIGH, at most VOL for a LOW.

VIH / VIL

The receiver's requirement: it reads HIGH only above VIH, LOW only below VIL.

Noise margin

The slack: NM(high) = VOH − VIH. Bigger margin rejects more noise before a bit flips.

Mismatch → shift

Different supplies (3.3 V vs 5 V) often break VOH ≥ VIH or exceed a pin's maximum — you must level shift.

A valid HIGH link needs the driver's VOH to clear the receiver's VIH; whatever is left over is the noise margin that keeps interference from being misread — the same margin that gives digital signals their noise immunity.

Worked example: an ESP32 output is powered from 3.3 V and its HIGH output is close to 3.3 V when lightly loaded. A 5 V TTL input may require only VIH = 2.0 V. The HIGH noise margin is therefore about 3.3 - 2.0 = 1.3 V. A cable transient or ground offset would have to steal more than 1.3 V before the receiver stops seeing a HIGH, so this direction is usually safe from a logic-threshold point of view.

The opposite direction is a different risk. A 5 V output connected directly to a 3.3 V microcontroller input may be read as HIGH, but it can exceed the input's absolute maximum rating. A correct review separates "will the bit be interpreted correctly?" from "will the pin survive?" That is why a circuit note should list both threshold margin and absolute-maximum protection, not just a casual statement that the voltages are close enough.

For beginner IoT boards, the practical checklist is simple: identify the driver supply, receiver supply, guaranteed output levels, required input thresholds, and pin maximum voltage. If any number is missing, do not assume compatibility. Look up the datasheet, add a level shifter, or constrain the interface to an open-drain bus with the correct pull-up rails.

20.4.1 Overview Knowledge Check

20.5 Check a Five-Volt Reply Before Connection

For this logic-level contract, a 3.3 V controller sends a clock to a 5 V sensor board and expects data back on another wire. A logic HIGH is not a universal voltage: the sender’s guaranteed output must cross the receiver’s input threshold without crossing its absolute limit. Figure 20.1 places VCCA and A1–A3 in the 3.3 V domain, VCCB and B1–B3 in the 5 V domain, and the translator between them. At the level-shifting boundary, read each rail before following a signal arrow.

In the digital link, an illustrative 5 V receiver with (V_{IH}=0.70\times V_{CC}) recognises HIGH from (0.70\times5=3.50\ \text{V}). For this logic-level contract, a 3.3 V output cannot meet that stated threshold, so a direct controller-to-sensor HIGH has negative margin. At the return level-shifting boundary, a 5 V output can exceed a non-tolerant 3.3 V input even though the bit value is correct.

An open-drain bidirectional bus needs a different check. With a 4.7 kΩ pull-up and an illustrative 50 Ω low-side resistance, the low node is (5\times50/(4700+50)=0.0526\ \text{V}), or 52.6 mV. That is safely near zero for many inputs, but pull-up value, bus capacitance, rise time, and the specific translator still decide whether the edge arrives on time.

20.5.1 Predict the Level-Shifter Boundary

Probe both voltage domains during a real bus exchange.

Power sequencing adds another logic-level contract. If the 5 V board stays on while the 3.3 V controller is off, a signal may feed current through an unpowered input. The translator datasheet must state its powered-off behaviour. A safe HIGH and LOW during normal use do not prove the link is safe during start-up or shutdown.

  • Predict: A resistor divider makes a 5 V output safe for a 3.3 V input. Can it also drive the reverse direction automatically? Check: No. A fixed divider only scales one driven direction and can distort a bidirectional bus.
  • Predict: Both datasheets call 2.0 V a valid HIGH at the relevant rails. Is a level shifter always required for that direction? Check: Not for threshold matching alone, but voltage limits, output type, speed, and power-off behaviour still need checking.

20.6 Practitioner: Shifting Down Is Easy, Shifting Up Is Not

The two directions are not symmetric. Going down (5 V → 3.3 V) mainly protects the lower-voltage input, whose absolute maximum is only a little above its own supply. For a slow, unidirectional push-pull signal a resistor divider is enough:

Vout = Vin × R2 / (R1 + R2). Put R1 = 1 kΩ in series from the 5 V signal and R2 = 2 kΩ to ground: Vout = 5 × 2 / (1 + 2) = 3.33 V — a safe HIGH for the 3.3 V input.

Going up (3.3 V → 5 V) is different. If the 5 V receiver is CMOS it needs VIH ≈ 0.7 × 5 = 3.5 V, and a 3.3 V output falls just short. A resistor divider cannot help — dividers only attenuate, never add voltage. You need something active: a MOSFET or transistor level-shifter, a dedicated level-translator IC, or an open-drain line with its pull-up tied to 5 V so the HIGH is pulled up to the higher rail.

Do not choose divider values by ratio alone. The divider above has total resistance 3 kΩ, so it draws 5 V / 3 kΩ = 1.67 mA whenever the input is HIGH. That is acceptable on a bench, but wasteful for a sleeping battery node. Scaling to 10 kΩ and 20 kΩ keeps the same 3.33 V output while reducing divider current to 0.167 mA. The tradeoff is edge speed: with 20 pF of input plus wiring capacitance, the Thevenin resistance is about 6.7 kΩ, giving an RC time constant near 134 ns. That is fine for a slow enable pin, but not a reason to use dividers casually on fast buses.

A practitioner review should also name the signal direction. A unidirectional "5 V interrupt output into ESP32 GPIO" can use a divider or translator. A bidirectional "3.3 V MCU and 5 V sensor share I2C" cannot be reviewed as two independent one-way signals, because either side may pull the line low. In that case, choose a bidirectional MOSFET shifter or a translator IC and size pull-ups for the bus speed and capacitance.

DirectionConcernTypical solution
5 V → 3.3 V (down)Overvoltage on the 3.3 V inputResistor divider (slow, one-way) or a level-translator
3.3 V → 5 V (up)3.3 V may be below the 5 V part's VIHActive shifter, translator IC, or open-drain pulled up to 5 V

20.6.1 Practitioner Knowledge Check

20.7 Under the Hood: Bidirectional Buses and Absolute Maximums

A resistor divider is not just up-shift-incapable — it is also unidirectional and speed-limited (its resistance and the line capacitance form an RC that softens fast edges). That fails a shared bus like I2C, where both sides must be able to drive the line. The standard trick is to make the lines open-drain with a pull-up on each side and place a single N-channel MOSFET per line (the classic BSS138 bidirectional shifter): when either side pulls low, the MOSFET couples the low across, and when released each side floats up to its own rail. That is why bus level-shifting looks different from a simple signal divider.

The reason down-shifting is mandatory, not optional, is the absolute-maximum input rating: a 3.3 V pin usually tolerates only about Vcc + 0.3 to 0.5 V before its internal clamp diodes conduct hard and it risks damage or back-powering its own rail. So drive a lower-voltage input from a higher-voltage source only through a proper shift — never by trusting the clamp diodes to survive a continuous overvoltage.

The MOSFET bus shifter works because the body diode and gate bias make a low level propagate across domains while released lines rise independently. On a 3.3 V / 5 V I2C link, the low side is pulled up to 3.3 V and the high side to 5 V. If the 3.3 V device pulls SDA low, the MOSFET conducts and drags the 5 V side low too. If the 5 V device pulls low, the body diode first nudges the low side down, then the MOSFET turns on and completes the low-level transfer. When neither device pulls, each side returns to its own safe HIGH.

Pull-up sizing is part of the evidence. With 4.7 kΩ pull-ups to 3.3 V, each LOW sinks about 3.3 V / 4.7 kΩ = 0.70 mA on that side. Stronger pull-ups such as 2.2 kΩ sharpen edges but increase sink current; weaker pull-ups reduce current but may fail rise-time limits on long wires. If a sensor board works at 100 kHz on a short jumper but fails at 400 kHz after the harness is installed, the level shifter may be electrically correct while the RC rise time is still too slow.

A final under-the-hood trap is back-powering. If a powered 5 V module drives a line into an unpowered 3.3 V microcontroller through its protection diode, the microcontroller rail can rise partially even though its regulator is off. That can create ghost boot states and latch-up risk. A robust design avoids continuous clamp current, sequences rails deliberately, or uses a translator with power-off isolation.

20.7.1 Under-the-Hood Knowledge Check