I2C/The two wires/5 V and 3.3 V

5 V and 3.3 V

A 5 V module's pull-ups hold the line at 5 V, which is on the ESP32's pins every time the line is a one. A one-transistor level converter gives each side its own wire at its own voltage.

Some I2C modules run at 5 V, and their pull-up resistors go to 5 V. Wire one straight to an ESP32 and every released line sits at 5 V, on the ESP32's pin. Espressif's datasheet allows an input no higher than the chip's supply plus 0.3 V, which on 3.3 V is 3.6 V. Five volts is over that every time the line is a one.

The fix is a level converter between them, and for I2C it is the one-transistor kind: an N-channel MOSFET on each line, gate on the 3.3 V supply, with a pull-up on each side to that side's own supply.

How one transistor passes a zero both ways

  • The ESP32 pulls its side down. The transistor's gate is at 3.3 V and its source now at 0 V, so it turns on and pulls the 5 V side down too.
  • The module pulls its side down. The transistor's built-in diode drags the 3.3 V side low enough to turn the transistor on, and it follows the rest of the way.
  • Nobody pulls. Each side's pull-up takes it to its own supply: 3.3 V for the ESP32, 5 V for the module.

Herman Schutte, one of the two engineers behind I2C, published the circuit at Philips in 1997, in application note AN97055. Our converter board uses a BSS138 on each channel with a 10 kΩ pull-up on each side.

Which converter

Not every level converter suits I2C. The TXB0108 drives its outputs itself and fights the pull-ups; Texas Instruments says not to use it on I2C. The logic level converter handbook compares the boards and says which to use for what.

Edit this page — content/fundamentals/i2c/five-volts-and-three.mdx

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Fundamentals on the forum →