Concept explainer · Intermediate · 3 min read
SPI Explained
Pins, Modes and Wiring Several Devices
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
SPI (Serial Peripheral Interface) is a fast four-wire bus: SCK carries the clock, MOSI carries data from the controller, MISO carries data back, and a separate chip-select (CS) line per device chooses who is listening. It runs at several to tens of megahertz, much faster than I2C, which is why displays, SD cards and radio modules use it. Share SCK, MOSI and MISO between devices and give each device its own CS pin.
Key specs at a glance
- Wires
- SCK, MOSI (COPI/SDO), MISO (CIPO/SDI), CS (SS), plus GND
- Speed
- Typically 1 to 80 MHz depending on chip and wiring
- Duplex
- Full duplex: sends and receives at the same time
- Modes
- 0 to 3, set by clock polarity (CPOL) and phase (CPHA)
- Devices
- One CS line per device, active LOW
- Distance
- Short: on-board or under about 30 cm of wire
How SPI works
The controller pulls a device's CS pin LOW to select it, then toggles SCK. On each clock pulse one bit goes out on MOSI and one bit comes back on MISO, so sending a byte also receives a byte. When the transfer ends, CS goes HIGH and the device ignores the bus again. There are no addresses, acknowledgements or start bits: the protocol inside each transfer is defined by the device's datasheet. Newer documents call the pins COPI (controller out, peripheral in) and CIPO; on modules you will also see SDI/SDO, DIN/DOUT or SDA/SCL on displays (still SPI).
SPI pins on common boards
| Board | SCK | MOSI | MISO | Default CS |
|---|---|---|---|---|
| Arduino Uno / Nano | 13 | 11 | 12 | 10 |
| Arduino Mega 2560 | 52 | 51 | 50 | 53 |
| ESP32 (VSPI) | 18 | 23 | 19 | 5 |
| ESP32-C3 (typical) | 4 | 6 | 5 | 7 |
| Raspberry Pi Pico (SPI0) | GP18 | GP19 | GP16 | GP17 |
| Raspberry Pi (SPI0) | GPIO 11 | GPIO 10 | GPIO 9 | GPIO 8 (CE0) |
- Arduino Uno / Nano
- SCK:
- 13
- MOSI:
- 11
- MISO:
- 12
- Default CS:
- 10
- Arduino Mega 2560
- SCK:
- 52
- MOSI:
- 51
- MISO:
- 50
- Default CS:
- 53
- ESP32 (VSPI)
- SCK:
- 18
- MOSI:
- 23
- MISO:
- 19
- Default CS:
- 5
- ESP32-C3 (typical)
- SCK:
- 4
- MOSI:
- 6
- MISO:
- 5
- Default CS:
- 7
- Raspberry Pi Pico (SPI0)
- SCK:
- GP18
- MOSI:
- GP19
- MISO:
- GP16
- Default CS:
- GP17
- Raspberry Pi (SPI0)
- SCK:
- GPIO 11
- MOSI:
- GPIO 10
- MISO:
- GPIO 9
- Default CS:
- GPIO 8 (CE0)
SPI modes and speed
Devices differ in whether the clock idles low or high (CPOL) and whether data is read on the first or second clock edge (CPHA). That gives modes 0 to 3; most sensors, SD cards and displays use mode 0. Set the mode, bit order and speed for each device with a transaction, which also lets devices with different settings share a bus.
#include <SPI.h>
const int CS = 10;
void setup() {
Serial.begin(115200);
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
SPI.begin();
}
uint8_t readRegister(uint8_t reg) {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(CS, LOW);
SPI.transfer(reg | 0x80); // many sensors: top bit set = read
uint8_t value = SPI.transfer(0x00);
digitalWrite(CS, HIGH);
SPI.endTransaction();
return value;
}
void loop() {
Serial.println(readRegister(0x0F), HEX); // e.g. a WHO_AM_I register
delay(1000);
}SPI vs I2C vs UART
| SPI | I2C | UART | |
|---|---|---|---|
| Wires | 4 + one CS per device | 2 shared | 2 per link (TX, RX) |
| Speed | Fast: MHz to tens of MHz | 100 kHz to 1 MHz | 9600 to about 1 Mbaud |
| Devices | Many, each with a CS pin | Up to about 100 by address | One to one |
| Typical uses | Displays, SD cards, radios (nRF24L01, LoRa), fast ADCs | Sensors, OLEDs, RTCs, port expanders | GPS, Bluetooth, GSM, debug console |
- Wires
- SPI:
- 4 + one CS per device
- I2C:
- 2 shared
- UART:
- 2 per link (TX, RX)
- Speed
- SPI:
- Fast: MHz to tens of MHz
- I2C:
- 100 kHz to 1 MHz
- UART:
- 9600 to about 1 Mbaud
- Devices
- SPI:
- Many, each with a CS pin
- I2C:
- Up to about 100 by address
- UART:
- One to one
- Typical uses
- SPI:
- Displays, SD cards, radios (nRF24L01, LoRa), fast ADCs
- I2C:
- Sensors, OLEDs, RTCs, port expanders
- UART:
- GPS, Bluetooth, GSM, debug console
Wiring tips for multiple devices
- Give each device its own CS pin and keep every unused CS HIGH, ideally with a 10 kΩ pull-up so devices stay quiet during boot.
- Keep wires short. Above a few megahertz, long jumper wires cause errors; lower the speed when debugging.
- Some SD card modules never release MISO, which blocks other devices. Use a module with a proper buffer, or a separate SPI bus (ESP32 and Pico have two).
- Match logic levels: many SPI modules are 3.3 V only. See logic level shifting.
- Read about the other buses in the I2C and UART guides.
Try it: UART, I²C and SPI transfer time calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Forgetting to set CS as an OUTPUT and HIGH at start-up.
- Using the wrong SPI mode for a device.
- Running long wires at high clock speeds.
- Sharing a bus with an SD module that holds MISO.
- Connecting 5 V SPI signals to a 3.3 V-only module.
Frequently asked questions
What does SPI stand for?
Serial Peripheral Interface, a synchronous serial bus that uses a clock line, two data lines and a chip-select line per device.
Is SPI faster than I2C?
Yes, typically ten to a hundred times faster, because it has separate data lines, push-pull outputs and no addressing overhead.
How many devices can be on an SPI bus?
As many as you have chip-select pins, since each device needs its own CS line. Some devices can also be daisy-chained.
What are MOSI and MISO?
MOSI (controller out, peripheral in) carries data from the microcontroller to the device; MISO carries data back. Newer names are COPI and CIPO.
Which SPI mode should I use?
Check the device datasheet. Most sensors, SD cards and displays use mode 0.
Parts for this guide
Terms in this guide
Keep learning
Sources
- Arduino SPI library reference
- Microcontroller datasheets: ATmega328P, ATmega2560, ESP32, RP2040 SPI peripherals
- Motorola SPI block guide (original definition of SPI modes)
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.




