Embedded systems frequently need to connect:
- sensors,
- displays,
- memories,
- converters,
- modules.
Three of the most common serial interfaces are:
- SPI,
- I2C,
- UART.
They solve different problems.
The correct choice depends on:
- speed,
- number of wires,
- number of devices,
- distance,
- software complexity,
- error handling.
Fundamentals and Technology Overview
Quick Comparison
| Feature | SPI | I2C | UART |
|---|---|---|---|
| Clock | Synchronous | Synchronous | Asynchronous |
| Typical topology | One host, multiple targets | Shared multi-device bus | Point-to-point |
| Data lines | Separate TX/RX | Shared SDA | TX/RX |
| Duplex | Full duplex | Half duplex | Full duplex |
| Addressing | Chip select | Built-in addresses | No bus addressing |
| Wiring | Higher | Low | Low |
| Typical use | High-speed peripherals | Sensors/configuration | Modules/debug |
What Is SPI?
SPI is a synchronous serial interface.
Typical signals include:
- SCLK,
- MOSI,
- MISO,
- chip select.
Microchip describes SPI as a short-distance high-speed synchronous bus that commonly uses three or four wires and supports full-duplex communication.
SPI Advantages
- high speed,
- simple protocol,
- full duplex,
- low software overhead.
SPI Limitations
- extra chip-select line per target,
- no standardized acknowledgment,
- more PCB pins.
Typical SPI Applications
- Flash memory,
- ADC,
- DAC,
- display,
- high-speed sensor.
What Is I2C?
I2C uses two shared signals:
- SDA,
- SCL.
Devices share the same bus and use addresses.
I2C Advantages
- only two wires,
- multiple devices on one bus,
- built-in addressing,
- acknowledgment.
I2C Limitations
- slower than SPI in many applications,
- pull-up resistors required,
- capacitance limits bus speed and length.
Typical I2C Applications
- temperature sensors,
- EEPROM,
- configuration ICs,
- RTC,
- low-speed sensors.
What Is UART?
UART is asynchronous serial communication.
Typical signals:
- TX,
- RX.
There is no shared clock line.
Both sides must agree on:
- baud rate,
- data bits,
- parity,
- stop bits.
Connectivity and System Integration
UART Advantages
- simple,
- point-to-point,
- useful over longer board-level distances than high-speed SPI.
UART Limitations
- no native multidrop addressing,
- lower data efficiency at some settings,
- both ends need compatible baud configuration.
Typical UART Applications
- GNSS modules,
- Bluetooth modules,
- debug console,
- modem.
Synchronous vs Asynchronous
SPI and I2C send an explicit clock.
UART derives timing from:
- agreed baud rate,
- start/stop bits.
Full Duplex
SPI can send and receive simultaneously using separate lines.
UART can also be full duplex with TX and RX.
I2C uses a shared data line and is effectively half duplex.
Device Count
SPI
Can support many devices, but each commonly needs a separate chip select.
I2C
Many addressed devices can share two wires.
UART
Usually one transmitter-receiver pair.
Speed
SPI is generally the fastest of the three.
Microchip cites common SPI rates around tens of MHz and much higher for dual/quad SPI.
I2C is optimized more for convenient multi-device communication than maximum throughput.
UART speed varies with hardware and distance.
Wiring
For a small PCB:
I2C
Best for minimizing pins.
SPI
Best when performance matters.
UART
Best for simple point-to-point links.
Pull-Ups
I2C uses open-drain/open-collector signaling with pull-up resistors.
SPI and UART commonly use push-pull outputs.
Addressing
I2C includes device addressing.
SPI normally selects devices using dedicated chip-select signals.
UART does not define a general shared-bus address mechanism.
Interface Design and Integration Tradeoffs
Protocol Overhead
SPI has low overhead.
I2C includes:
- start,
- address,
- acknowledgment,
- stop.
UART includes framing bits.
Error Detection
UART may use:
- parity.
I2C provides:
- ACK/NACK.
SPI does not inherently guarantee delivery.
Applications may add:
- CRC,
- response packets.
Distance
All three are mainly board-level interfaces in their basic electrical form.
For long cable runs, use physical-layer transceivers such as:
- RS-485,
- CAN.
Noise
Fast single-ended PCB signals are more sensitive to:
- routing,
- ground reference,
- cable length.
Multi-Master
I2C can support multi-controller operation.
SPI is normally one host controlling the bus.
UART has no standard multi-master arbitration.
Clock Stretching
Some I2C targets can delay communication using clock stretching.
The host must support it correctly.
SPI Modes
SPI has different clock polarity and phase combinations.
Both devices must agree on:
- CPOL,
- CPHA.
UART Baud Error
The receiver must recover timing without a shared clock.
Excessive oscillator mismatch can cause errors.
DMA
All three interfaces can benefit from DMA when transferring large amounts of data.
Interrupts
Peripheral interrupts can notify firmware when:
- receive data arrives,
- transfer completes.
Applications and Practical Examples
Example: External Flash
Use:
SPI
because storage requires high throughput.
Example: Environmental Sensors
Use:
I2C
when several low-speed sensors share the same board.
Example: GNSS Module
Use:
UART
because the module commonly streams serial text or binary packets.
Example: ADC
Use SPI when:
- sample rate is high,
- deterministic transfer matters.
Example: Configuration EEPROM
I2C is often sufficient.
Cost
The cost difference is usually dominated by:
- MCU pins,
- connector,
- PCB routing.
Power
Lower clock rates generally reduce switching power.
I2C pull-ups also consume current during low states.
Common Mistake: Choosing SPI for Too Many Devices
Chip-select routing can become messy.
Common Mistake: Long I2C Cable
Bus capacitance can create reliability problems.
Common Mistake: UART Without Error Recovery
For critical links, add:
- checksum,
- timeout,
- retry.
Selection Guide
Choose SPI when:
- high speed matters,
- devices are close,
- extra pins are acceptable.
Choose I2C when:
- many low-speed devices share two wires.
Choose UART when:
- simple point-to-point asynchronous communication is needed.
Conclusion
SPI, I2C, and UART are complementary rather than competing interfaces.
The main trade-off is:
speed vs wiring vs topology.
Use SPI for performance, I2C for convenient multi-device sensor buses, and UART for simple point-to-point communication.