</>EmbeddedInterview

What is the difference between open-drain and push-pull outputs?

EasyMicrocontrollers & ARM Cortex-M

Short answer: A push-pull output has two transistors (one to the supply, one to ground) and actively drives the line both high and low, giving strong, fast edges. An open-drain (open-collector for bipolar transistors) output has only the transistor to ground: it can pull the line low or release it; a pull-up resistor makes the line high when released. Open-drain lets several devices share one line safely and lets the line be pulled up to a different voltage.

Push-pull                     Open-drain
  VDD                           VDD (or another voltage)
   |                             |
  [P-MOS]                       [R pull-up]
   |---- output                  |---- line
  [N-MOS]                       [N-MOS]
   |                             |
  GND                           GND
Push-pull Open-drain
Drives high actively via pull-up resistor (passive)
Rise time fast depends on R × C of the line
Several outputs on one line short circuit if one drives high and another low safe: any device can pull low ("wired-AND")
High level voltage the chip's supply whatever the pull-up connects to (within the pin's tolerance)
Power no static current current flows through the pull-up while low
Typical uses LEDs, SPI, UART TX, chip select I2C SDA/SCL, shared interrupt/reset lines, 1-Wire, level shifting

Why I2C needs open-drain: several devices (controller and targets) drive SDA, and clock stretching and arbitration require that any device can hold the line low while others release it. With push-pull outputs, two devices driving opposite levels would short the supply.

Choosing the pull-up value: a smaller resistor gives faster rising edges but more current when the line is low. For I2C, typical values are 2.2–10 kΩ, calculated from the bus capacitance and speed (see the Communication Protocols topic).

Level shifting trick: a 3.3 V MCU can drive an open-drain line pulled up to 5 V only if the pin is 5 V tolerant (marked "FT" on STM32). Otherwise use a level shifter.