Learn / Communication / UART and SPI

SPI, UART & Interface Trade-offs

ReviewedIntermediate MakerAbout 5 min
NRF24
In short

SPI, UART & Interface Trade-offs: the short answer

UART is the simplest serial link: TX of one side to RX of the other, plus ground. Both sides must agree on the speed, the baud rate, such as 9600 or 115200.

Level
Intermediate
Time
About 5 min
Topic
Communication
You will learn to

Wire UART and SPI devices correctly and choose between UART, SPI and I²C.

Before this: I²C Addressing & Shared Buses

UART is the simplest serial link: TX of one side to RX of the other, plus ground. Both sides must agree on the speed, the baud rate, such as 9600 or 115200. It is what the serial monitor uses, and what GPS modules and HC-05 Bluetooth modules speak.

SPI is faster and uses a clock: SCK (clock), MOSI (controller out), MISO (controller in) and one CS (chip select) line per device. Many devices share SCK, MOSI and MISO; each gets its own CS. Displays like the ILI9341, SD card modules and the RC522 RFID reader use SPI.

I²C uses fewer wires; SPI is faster and simpler to debug with a scope; UART is point to point. Check voltage levels with all three: a 5 V TX into a 3.3 V RX needs a divider or level shifter.

How SPI moves data

SPI is a shift register arrangement: on every clock pulse one bit goes out on MOSI and one comes in on MISO, so sending and receiving happen at the same time. The controller sets a device's chip-select low to talk to it and high to ignore it. There is no addressing and no acknowledgement, so a missing device simply reads as all ones or all zeros.

Speeds run from a few hundred kHz to tens of MHz, far faster than I²C. That is why displays, SD cards and fast ADCs use SPI.

SPI modes and settings

Each device expects the clock to idle high or low (CPOL) and to sample data on the first or second edge (CPHA). Together they make four modes, numbered 0 to 3. A mismatch gives wrong or garbled data with no error. The datasheet states the mode; most devices use mode 0. Check also the maximum clock speed and the bit order, which is most significant bit first for nearly everything.

If a device returns garbage, slow the clock first, then check the mode, then the wiring. Keep the wires short, and add a series resistor of about 100 Ω on a fast clock line if edges ring.

UART details

A UART has no clock, so both ends rely on matching baud rates; a few percent of mismatch breaks it. Hardware flow control lines (RTS and CTS) let a receiver tell the sender to wait, and are used on fast links such as Bluetooth modules. RS-232 uses voltages up to ±12 V and needs a converter chip (such as a MAX3232) before it meets a microcontroller; RS-485 sends data on a differential pair over long distances and many devices can share the bus.

A GPS module sending a line of text every second is a good example of a UART device: read characters into a buffer until a newline, then process the line.

Choosing between the three

Use I²C for slow sensors, many devices and few wires. Use SPI when speed matters, as for displays and storage, and accept more wires. Use UART for point-to-point links, modules that speak text commands, and long runs with RS-485. When the pin count is tight, I²C wins; when the data rate is high, SPI does.

Common mistakes
  • Forgetting to pull chip-select high for devices you are not using, so two devices answer at once.
  • Using the wrong SPI mode and seeing plausible but wrong data.
  • Mixing 5 V and 3.3 V signals without level shifting.
Key formulas
t = (1 + data + parity + stop) ÷ baud
time for one UART character

Work it with your own numbers: UART frame time

Intermediate lesson · Maker plan

Practise this lesson with Maker

The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.

With Maker you also get: a worked example, a hands-on task, a 3-question check.

Common questions

What will I learn in "SPI, UART & Interface Trade-offs"?

Wire UART and SPI devices correctly and choose between UART, SPI and I²C.