What is SPI?

Serial Peripheral Interface: synchronous serial communication in which data is exchanged in both directions on a master-driven clock, with devices selected by chip-select lines. Used for fast parts.

Field: Embedded Systems & Firmware

Japanese name: SPI

Signals and the shift-register model

SPI uses a clock (SCLK) driven by the master, a master-to-slave data line (MOSI, also called COPI), a slave-to-master line (MISO, also CIPO; the pin names SDO and SDI on a part mean output and input as seen from that part) and an active-low chip select (CS) per slave. Inside, master and slave each hold a shift register, and the two registers form a ring: on every clock one bit leaves the master while one bit enters it. Transfers are therefore always full duplex. To read from a device, the master must still clock out bytes, often dummy ones. SPI has no addresses and no acknowledge; selecting a device is done purely with its CS line.

Clock polarity and phase: the four modes

Two settings define an SPI mode. CPOL sets the idle level of the clock, and CPHA chooses whether data is sampled on the first or second clock edge after CS goes active. The four combinations are modes 0 to 3; in mode 0 the clock idles low and data is sampled on the rising edge, and in mode 3 it idles high and is also sampled on the rising edge. If master and device disagree, sampling shifts by half a clock period and bits are shifted or garbled, so the datasheet's mode, bit order and maximum clock rate are the first things to check.

SPI versus I2C and UART

SPI's push-pull outputs and dedicated lines allow clock rates of tens of MHz, which is why flash memory, displays and fast ADCs use it. The cost is wiring: every additional device needs another CS line. I2C shares two open-drain lines with pull-up resistors among many devices, selects them by address and acknowledges each byte, but the pull-ups limit it to about 100 kHz to a few MHz. A UART links just two devices asynchronously, with no clock wire, relying on both sides agreeing on the baud rate. The choice depends on speed, pin count and what the parts support.

Variants you will meet

Serial flash and some displays extend the basic scheme. Dual and quad SPI turn the data lines into two or four bidirectional lines, roughly doubling or quadrupling read throughput, and some microcontrollers can execute code directly from quad SPI flash. Several devices can also be daisy-chained, passing data through each shift register in turn so they share one CS. Because SPI has no built-in flow control or error checking, protocols built on top often add status registers, busy flags or checksums.

Try it: questions about SPI

What is a characteristic of SPI communication?

  1. AIt is asynchronous without a clock, using only two wires
  2. BIt is synchronous with the master driving the clock, sends and receives simultaneously, and selects devices with chip-select lines
  3. CIt selects devices by address, so two wires suffice for any number of devices
Show answer and explanation

Answer: B. It is synchronous with the master driving the clock, sends and receives simultaneously, and selects devices with chip-select lines

SPI is synchronous communication in which, on the clock driven by the master, data flows simultaneously on a master-to-slave line and a slave-to-master line. Each device gets its own chip-select (CS) line, and only the device whose CS is pulled low communicates. Its simplicity allows clocks of tens of MHz, so it often connects fast parts such as flash memory, displays and ADCs.

Which set of four signals is generally used by SPI?

  1. ASDA and SCL, plus power and ground
  2. BSCLK (clock), MOSI (master out), MISO (master in) and CS (chip select)
  3. CTX and RX, plus RTS and CTS
Show answer and explanation

Answer: B. SCLK (clock), MOSI (master out), MISO (master in) and CS (chip select)

In SPI, the master drives the clock on SCLK, sends data on MOSI (master out, slave in) and simultaneously receives data on MISO (master in, slave out). CS selects which slave to talk to, so three slaves normally need three CS lines. MOSI and MISO also go by other names, such as COPI and CIPO or SDO and SDI.

FAQ

How many wires does SPI need?

Basic SPI uses four signals, SCLK, MOSI, MISO and CS, plus ground. Each additional slave normally needs its own CS line, while three-wire variants combine the two data lines into one.

What is SPI mode 0?

Mode 0 means CPOL = 0 and CPHA = 0: the clock idles low and data is sampled on the rising edge. It is the most widely supported mode, but the device datasheet decides which mode must be used.

Is SPI faster than I2C?

Generally yes. SPI's push-pull signaling commonly runs at tens of MHz, while open-drain I2C buses typically run from about 100 kHz to a few MHz.

Questions that mention SPI (3)

SPI appears in 5 practice questions across 2 topics, including Embedded Systems & Firmware, CPUs and architecture.

  1. When an SPI part is connected but correct data cannot be read, which setting is most worth checking?
  2. Which comparison of UART, SPI and I2C is correct?
  3. Which IC integrates a CPU, memory and peripherals such as timers and ADCs on one chip and is used to control appliances and equipment?

Books on Embedded Systems & Firmware Ad

Learn hands-on: parts and kits

Building real circuits is a good way to check what you learned in the questions.

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary