Logic Levels and Interfacing
Connect real digital parts together safely: check level compatibility from datasheet numbers, choose the right level shifter, and size pull-ups for open-drain buses.
Two ways in. Work the material, or if you already know this, go straight to the project and prove it.
Where this sits
How this skill is structured
- 1. Concepts — the ideas stated plainly, with the equations worth memorising.
- 2. Worked example — one real problem solved end to end, numbers included.
- 3. Tool demonstration — do the thing in a real open-source tool.
- 4. Resources — the specific free readings and videos, and what part of each to use.
- 5. Project — built alone, producing something a reviewer can check.
- 6. Competence checklist — what you must be able to do. This is also the audit rubric.
1. Concepts
Read these first. Tick each one when you could explain it to someone else without notes.
2. Worked example
Sizing I2C pull-ups for a 400 kHz bus with mixed voltages
ProblemA 3.3 V microcontroller talks I2C at 400 kHz to two sensors, one 3.3 V and one 1.8 V. Total bus capacitance is estimated at 150 pF on the 3.3 V side. Design the pull-ups and the level shift.
- 1Level shift first: I2C is open-drain, so the standard single-MOSFET bidirectional shifter works. One small-signal N-channel MOSFET per line, source to the 1.8 V side, drain to the 3.3 V side, gate to 1.8 V.
- 2For this to work the MOSFET's Vgs(th) must be well below 1.8 V. Check a real part: a BSS138 has Vgs(th) between 0.8 and 1.5 V. The 1.5 V maximum leaves only 0.3 V of overdrive — marginal. A part with Vgs(th) max of 1.0 V is a better choice.
- 3Now the pull-ups. The circuit needs a pull-up on both sides: one to 3.3 V, one to 1.8 V.
- 4R_min from the sink capability. I2C fast mode requires devices to sink 3 mA while holding VOL below 0.4 V. R_min = (3.3 - 0.4) / 0.003 = 967 ohm on the 3.3 V side. On the 1.8 V side: (1.8 - 0.4) / 0.003 = 467 ohm.
- 5R_max from the rise time. I2C fast mode allows a maximum rise time of 300 ns. The bus rises exponentially from VIL to VIH, conventionally 30% to 70% of the rail, which takes 0.847 x R x C. So R_max = 300e-9 / (0.847 x 150e-12) = 2361 ohm on the 3.3 V side.
- 6The window on the 3.3 V side is therefore 967 to 2361 ohm. Choose 1.5 k (E24) — comfortably inside, closer to the fast end.
- 7Check the actual rise time with 1.5 k: t = 0.847 x 1500 x 150e-12 = 191 ns. Within the 300 ns limit with 36% margin.
- 8Check the sink current with 1.5 k: 3.3 / 1500 = 2.2 mA. Within the 3 mA the devices must sink, so VOL will be comfortably below 0.4 V.
- 9The 1.8 V side sees less capacitance (fewer devices) — say 60 pF. R_max = 300e-9 / (0.847 x 60e-12) = 5900 ohm. R_min = 467 ohm. Choose 2.2 k.
- 10Static power: the bus is low roughly half the time during transfers. Average current on the 3.3 V side ~ 1.1 mA per line, so 2.2 mA for SDA and SCL together. On a battery-powered design this is significant and argues for larger pull-ups plus a slower bus, or for powering the bus down between transactions.
- 11Finally check the level shifter does not break the timing: the MOSFET's body diode pulls the low side down when the high side is driven low, and the pull-ups do the rising edges. The rise time on the low-voltage side is what you calculated; the MOSFET adds a little capacitance. Add 10-20% margin.
Answer1.5 k to 3.3 V and 2.2 k to 1.8 V, with a low-threshold N-channel MOSFET per line as the bidirectional shifter. Rise time 191 ns against a 300 ns limit; sink current 2.2 mA against a 3 mA capability. Both the minimum and the maximum came from datasheet numbers, not from a rule of thumb.
3. Tool demonstration
Simulate the pull-up rise time, then measure it on a real bus and compare.
4. Resources
Free and, wherever possible, openly licensed. The note tells you which part to actually use — do not read them cover to cover.
5. Project — build this on your own
About 3 hours. This is the artifact that proves the skill. Work it without a walkthrough.
Design and verify the complete interface layer for a mixed-voltage system: a 3.3 V microcontroller connecting to a 5 V push-pull peripheral, a 1.8 V I2C sensor, and a 5 V open-drain interrupt line, plus one signal you must prove is safe without any shifter.
Deliverables
Acceptance criteria — how you know it is good enough
If you want to push further
- Add bus capacitance measurement: estimate the bus capacitance from a measured rise time and a known pull-up, then verify by adding a known capacitor.
- Design the same interface set for a battery-powered device where static pull-up current matters, and quantify the energy saved by your changes over a day of operation.
6. Competence checklist
Tick these honestly. If you are auditing this skill, this is your rubric — you should be able to demonstrate every line from the project you just built.