SPI vs. I2C: Which Communication Protocol Should You Use?

SPI vs. I2C: Which Communication Protocol Should You Use?

Connecting a microcontroller to sensors, memory chips, converters, or displays almost always comes down to a choice between two synchronous serial interfaces: SPI and I2C.

Both move data over short distances inside a single assembly, but they use different wiring, addressing, and electrical rules. The SPI vs. I2C decision affects pin assignments, pull-up placement, trace routing, and how many peripherals a design can support.

The right interface depends on the system's performance and physical constraints, not a fixed ranking between the two. This article explains how each protocol works, compares them side by side, and covers the design details that determine whether a bus performs reliably.

Key Takeaways

Side-by-side comparison of SPI's dedicated chip-select wiring versus I2C's shared two-wire bus with pull-up resistors.
Side-by-side comparison of SPI's dedicated chip-select wiring versus I2C's shared two-wire bus with pull-up resistors.

How SPI and I2C Work

SPI and I2C both move digital data between a controller and peripherals, but with different signal architectures.

SPI: Four Signals, One Select Line Per Device

Serial Peripheral Interface (SPI) connects a controller (older datasheets say "master") to peripherals (older datasheets say "slaves") over four lines. Each line has a different role in coordinating communication between the controller and the selected peripheral:

  • SCLK: clock signal, generated by the controller, sets the data rate.
  • MOSI: data from the controller to the selected peripheral.
  • MISO: data back to the controller.
  • Chip select (CS): one dedicated line per peripheral, pulled low to activate that device.

MOSI and MISO are separate lines, so SPI transfers in both directions at once. Full-duplex operation is one reason SPI reaches higher throughput than I2C.

I2C: Two Shared Signals, Addressed Devices

Inter-Integrated Circuit (I2C) uses two lines shared by every device on the bus:

  • Serial Data (SDA): data, carried in both directions, one direction at a time.
  • Serial Clock (SCL): clock signal, generated by the controller.

Every I2C device has a fixed or configurable address, so the controller selects a peripheral by address instead of a dedicated pin. Both lines use open-drain outputs, so a device can only pull a line low, never drive it high. External pull-up resistors return each line to the supply voltage between transmissions.

SPI vs. I2C Comparison

The table below lines up SPI and I2C across the factors that matter most for schematic and layout decisions.

SPI vs. I2C Characteristic Comparisons

Characteristic SPI I2C
Signal lines 3 shared lines (SCLK, MOSI, MISO) plus one CS per peripheral 2 shared lines (SDA, SCL) for the entire bus
Device selection Dedicated chip-select line per peripheral Device address sent over the shared bus
Typical throughput Several MHz to tens of MHz, device- and layout-dependent Commonly 100 kHz to 1 MHz, faster on some devices
Duplex operation Full duplex Half duplex
Addressing Not required; selection is physical Required; each device needs a unique address
Pull-up requirements Normally none Required on both SDA and SCL
Multi-device scalability Limited by available CS pins Many devices on two wires, limited by address space
Implementation complexity Simple protocol, more pins to manage Slightly more overhead, fewer pins
PCB routing More traces, no pull-up network Fewer traces, plus a pull-up network
Common applications Displays, ADCs/DACs, flash memory, fast sensors Config and moderate-speed sensors, EEPROMs, RTCs, I/O expanders

Practical speed depends on the specific devices, bus capacitance, and layout, not only the protocol's specification. A short, well-laid-out bus at a moderate clock rate often outperforms a longer bus pushed toward its limit.

Electrical and PCB Design Considerations

SPI and I2C are both intended for short-distance communication within an assembly. Several electrical details separate a reliable bus from an intermittent one.

  • I2C pull-up sizing: depends on bus capacitance and target speed. Too high slows the rising edge; too low wastes power.
  • Bus capacitance and rise time: every device and trace adds capacitance; long buses may need lower pull-up resistance or a buffer.
  • SPI chip-select routing: keep each CS trace close in length to its SCLK trace so a device doesn't sample early.
  • Signal return paths: route clock and data over a continuous ground plane underneath the signal.
  • Trace length and clock rate: faster clocks make length and loading more sensitive.
  • Series termination: a small series resistor near the driver can damp reflections on longer SPI traces.
  • Voltage-level compatibility: confirm all devices share a logic level; I2C pull-ups reference one supply rail.
  • Connector and off-board limits: cables add capacitance and noise, so keep off-board runs short.
  • Logic-analyzer test points: accessible points on the clock and data lines simplify bring-up.

When to Choose SPI or I2C

Choosing an interface comes down to pin budget, throughput, and how many peripherals share the bus.

Choose SPI when:

  • Higher data throughput is required, such as when transferring large amounts of data quickly.
  • Full-duplex communication is useful, such as reading and writing memory at once.
  • Only a small number of peripherals are required.
  • Extra chip-select traces fit the routing budget.
  • The peripheral's datasheet requires SPI for full performance.

Choose I2C when:

  • Minimizing pin count matters more than raw speed, such as fitting within tight ESP32 or Raspberry Pi GPIO budgets.
  • Several moderate-speed devices share one bus.
  • Addressable sensors or configuration devices are involved.
  • Board space and routing simplicity are priorities.

Neither protocol fits every case. Long cable runs or noisy environments often favor CAN or RS-485. High-throughput streaming may call for USB, and simple point-to-point links to a PC sometimes work better over UART.

Example: Connecting Sensors and Memory to a Microcontroller

A common mixed-interface design uses one microcontroller with two I2C sensors, an SPI display or ADC, and SPI flash memory for data logging.

SPI and I2C coexist on the same board without conflict. The I2C sensors share one SDA and one SCL line. A resistor pair pulls both lines high, with resistance selected according to the combined bus capacitance. The SPI display or ADC and the SPI flash share SCLK, MOSI, and MISO. Each peripheral has a dedicated CS line connected to the controller.

On the PCB, the shared I2C pair routes to both sensors with short stubs over a solid ground return. The SPI group keeps each CS trace matched to SCLK and keeps flash traces short, since flash often runs at the board's highest clock rate. Designers should map both buses, verify pull-up placement, and run design rule checks on trace lengths directly in Flux before fabrication.

Choosing the Right Bus for Your Design

The SPI vs. I2C decision comes down to matching pin budget, throughput needs, device count, and board space, not picking a universal winner. Once chosen, schematic connectivity, pull-up selection, chip-select routing, and layout determine whether the bus performs reliably. Flux supports both, letting designers use shared libraries, run automated rule checks, and review pull-up and chip-select routing before manufacturing. Start mapping your SPI or I2C bus in Flux.

FAQs

More in PCB Design & Engineering Fundamentals

Let’s start building.

Let’s build your idea together. All you need to do is describe what you want to make, or what problem you want to solve. Flux will work with you to make it a reality.

Try it Free
Close-up of a Flux-designed printed circuit board