What Is SPI?
SPI (Serial Peripheral Interface) is a four-line interface that transfers high-speed synchronous serial data between devices. For a general comparison see the what are UART, SPI, I2C article.
Four Lines
The basic lines: MOSI (data from master to slave), MISO (data from slave to master), SCK (clock) and CS/SS (chip select). The clock is generated by the master.
Chip Select (CS)
Each slave has a separate CS line. The master selects the device it wants to talk to by activating its CS line. Many devices are connected, each with its own CS.
| Property | Value |
|---|---|
| Line count | 4 (+CS per device) |
| Speed | Very high |
| Direction | Simultaneous (full-duplex) |
Difference From I2C
I2C connects many addressed devices with two lines but is slower; SPI is faster and carries data in both directions at once, but needs an extra CS line for each device.
Where Is It Used?
TFT displays, Flash memory, SD cards, high-speed ADC/DAC and fast sensors.
Daisy-Chaining
Some SPI devices can be chained so that one device's output connects to another's input; so multiple devices can be driven with a single CS line. This method saves pins but, since it requires shifting data through the whole chain, the software is a bit more complex.
Common Mistakes
- Mode mismatch: the clock polarity/phase (CPOL/CPHA) must be the same on both sides.
- CS management: driving the wrong CS selects the wrong device.
- Line count: with many devices the CS pins run out quickly.
Frequently Asked Questions
Why is SPI fast?+
What are CPOL/CPHA?+
Search parts related to "What Is SPI?"
Find the right part by comparing price, stock and distributors.