UART vs SPI vs I2C: Wires, Speed and Timing Compared
UART, SPI and I2C are the three serial buses almost every microcontroller has. They all move bytes one bit at a time, but they differ in how many wires they need, who sets the timing, how a device is chosen and how fast they go. This page puts them side by side, shows one frame of each, and works out how long the same 16 bytes take on each bus.
Learning objectives
- Name the wires of UART, SPI and I2C and say which device drives each
- Read one frame of each bus from a timing diagram
- Count the bits on the wire for a transfer, including framing and acknowledgments, and turn that into a time
- Choose a bus for a sensor, a display, a flash chip or a debug console, and explain why
Prerequisites
- Binary and hexadecimal, and what a clock edge is
- No prior bus experience
The three buses at a glance
| UART | SPI | I2C | |
|---|---|---|---|
| Wires | TX and RX (plus ground) | SCLK, MOSI, MISO and one CS per device | SCL and SDA, shared by every device |
| Clock | None: both ends agree on a baud rate | Driven by the master | Driven by the master; a slave may hold it low |
| Choosing a device | Point to point: one device per pair of wires | A chip select line per device | A 7-bit address in the first byte |
| Direction | Full duplex | Full duplex | Half duplex |
| Acknowledgment | None | None | Every byte is ACKed or NACKed |
| Typical speed | 9600 to 921600 baud | 1 to 50 MHz and more | 100 kHz, 400 kHz, 1 MHz |
| Driver type | Push-pull | Push-pull | Open drain with pull-up resistors |
| Typical use | Debug console, GPS, Bluetooth modules | Flash, displays, ADCs | Sensors, EEPROMs, power monitors |
UART: a frame with no clock
A UART has no clock wire, so the receiver has to know the bit time in advance. Each byte travels in a frame: the line idles high, a start bit pulls it low, eight data bits follow least significant bit first, and a stop bit returns it high. The format is written 8N1: 8 data bits, no parity, 1 stop bit. The receiver starts timing at the falling edge of the start bit and samples each bit in its middle. That is why both ends must agree on the baud rate to within a few percent.
SPI: a clock and a select line
SPI adds a clock wire that the master drives, so there is no rate to agree on: the slave just follows SCLK. The master pulls one chip select line low to choose a slave, then shifts a bit out on MOSI and in on MISO on every clock, so it sends and receives at the same time. There is no framing and no acknowledgment, so every bit on the wire is data, and the clock can run at tens of megahertz. The price is wires: each extra slave needs its own CS line. The two settings CPOL and CPHA decide which clock edge carries the data; Part 2 covers them.
I2C: two wires, addresses and ACK
I2C needs only two wires for any number of devices. Both are open drain: a device can only pull a line low, and a pull-up resistor lets it rise. The master starts a transfer with a START condition, then sends a byte with a 7-bit address and a read or write bit; only the device with that address answers, by pulling SDA low for a ninth clock, the ACK. Every byte after that is also acknowledged. The pull-ups make the edges slow, which is why I2C runs at 100 kHz or 400 kHz rather than megahertz. Part 3 takes it apart.
Worked example: 16 bytes on each bus
To compare them fairly, count every bit time the transfer occupies on the wire. For 16 bytes: UART sends 10 bits per byte. SPI sends exactly 8 clocks per byte. I2C sends a START, an address byte and a register byte, each with its ACK (9 bit times each), then 9 bit times per data byte and a STOP.
| Bus | Bit times for 16 bytes | Time | Share that is data |
|---|---|---|---|
| UART 115200 baud, 8N1 | 160 | 1388.9 us | 80% |
| SPI 10 MHz | 128 | 12.8 us | 100% |
| I2C 100 kHz | 164 | 1640.0 us | 78% |
| I2C 400 kHz | 164 | 410.0 us | 78% |
SPI at 10 MHz is about a hundred times faster than the other two, because its clock is faster, not because its framing is leaner: UART and I2C waste about the same share of the wire (20 and 22 percent). I2C at 100 kHz is the slowest here, but it reached a device on a shared two-wire bus with an address and got every byte acknowledged, which UART and SPI cannot do.
Choosing a bus
- A debug console, a GPS or a Bluetooth module: UART. Two wires, no clock, and every terminal program speaks it.
- A flash chip, a display or a fast ADC: SPI. It is the only one of the three fast enough for megabytes or a video frame.
- Several slow sensors on one board: I2C. Two wires for all of them, and an ACK tells the firmware the device is there.
- Long cables or a noisy environment: none of these as they are. RS-485 (UART over a differential pair) or CAN, as in the CAN bus project, are built for that.
Common mistakes
- Crossing UART wires wrongly: one side's TX goes to the other's RX. Connecting TX to TX gives silence.
- Comparing buses by clock rate alone. Count the bits on the wire: framing, addresses and ACKs all take time.
- Forgetting the I2C pull-ups. With open drain outputs, nothing drives the lines high without them.
- Sharing SPI's MISO between slaves whose outputs do not release the line when deselected. Part 2, exercise 4, shows the result.
- Mismatched baud rates on a UART: the first byte may look almost right, and the errors grow toward the end of each frame.
Quick check
1. Which of the three buses can tell the master that a device is not present?
I2C: an absent device leaves SDA high during the ACK clock, so the master sees a NACK. UART and SPI send blindly.
2. How many bit times does one byte take on a UART set to 8N1?
10: a start bit, 8 data bits and a stop bit.
3. Why does an SPI slave not need to know the clock rate in advance?
The master sends the clock on SCLK, and the slave samples on its edges. A UART receiver has no clock wire, so it must time the bits itself.
Exercises
E1 (easy). How long do 100 bytes take over a UART at 9600 baud, 8N1?
1000 bit times at 9600 bits a second: 104.2 ms.
E2 (medium). An EEPROM page write of 32 bytes: I2C at 400 kHz against SPI at 10 MHz. The I2C part takes a 2-byte memory address; the SPI part takes an opcode and a 2-byte address.
I2C: START, address byte, 2 address bytes and 32 data bytes, each 9 bit times, and a STOP: 317 bit times, 792.5 us. SPI: 35 bytes of 8 clocks: 28 us. SPI is 28 times faster. Both chips then need several milliseconds to program the page, which often matters more.
E3 (medium). A UART divides a 16 MHz clock by 16 times a whole-number divisor. How close can it get to 115200 baud, and is that close enough?
The nearest divisor is 9, giving 111111 baud, 3.55 percent slow. The receiver samples the stop bit 9.5 bit times after the start edge, and that sample must stay within half a bit of the middle, so in theory the two ends may differ by less than 5.3 percent in total. 3.55 percent at one end uses most of that budget, so it works only if the other end is accurate and the edges are clean. A clock such as 18.432 MHz, which divides exactly, or a UART with a fractional divider removes the error.
E4 (hard). A sensor is read 1000 times a second: 6 bytes from a register, over I2C at 100 kHz. How busy is the bus?
Each read is a register write and a read with a repeated START: 84 bit times, 840 us. A thousand of them take 840 ms of every second: the bus is 84 percent busy, with no room for another device. Moving to 400 kHz cuts it to 21 percent; for more, the sensor's SPI interface, if it has one, is the better choice.
Interview questions
- Q1. Why does I2C need pull-up resistors and SPI does not? Answer: I2C outputs are open drain, so several devices can share a line and a slave can hold SCL low without a short circuit; the resistor pulls the line high when nobody pulls it low. SPI outputs are push-pull and drive both levels.
- Q2. You need to talk to 8 identical sensors with the same fixed I2C address. What are your options? Answer: an I2C multiplexer that connects one branch at a time, separate I2C controllers, or parts with address pins set to different values.
- Q3. A UART link works at 9600 baud but corrupts bytes at 115200. What do you check first? Answer: the baud rate error of each end's divisor at the higher rate, then signal integrity: cable length and edges.
Summary
- UART: two wires, no clock, point to point, 10 bit times per byte at 8N1.
- SPI: a master-driven clock, a chip select per device, full duplex, fastest of the three.
- I2C: two open drain wires shared by many devices, with addresses and an ACK after every byte.
- Compare buses by counting every bit time on the wire, not by the clock rate alone.
Related
Sources
Last verified
Every number on this page was computed and checked on 27 November 2026.