Serial Peripheral Interface (SPI) is a synchronous serial communication protocol commonly used in microcontrollers and embedded systems. On Arduino boards, SPI enables fast, efficient communication with various external peripherals such as sensors, memories and wireless communication modules. This protocol is appreciated for its simplicity, speed and flexibility.
The SPI link is synchronous, which means that transmission requires the clock given before transmission.
It’s a full-duplex link, which means that you can listen to what you’re transmitting while sending bits.
It’s not an exclusive link: the circuits communicate according to a master-slave scheme, where the master takes care of all communication. Several slaves can coexist on the same bus, in which case selection of the recipient is made via a dedicated line between master and slave called chip select, as shown in the diagram below:
SPI has lines labeled “MOSI”: Master Output Slave Input, generated by the master, lines labeled “MISO”: Master Input Slave Output, generated by the slave, and a clock line (SCK: SPI Serial Clock).
These three lines are connected to their respective lines on one or more slaves. Slaves are identified by their CS (Chip Select) line signal.
On Arduino boards, the pins dedicated to SPI vary according to the board model. For example, on an Arduino Uno, the SPI pins are :
Arduino simplifies the use of SPI with its SPI.h library. Here’s a basic example of how to use this library to communicate with an SPI device:
The following program sends byte 42 via the SPI wires.
If you want to read the values on the SPI of the Arduino board :
If you’d like to know more about the communications buses available on Arduino, we’ve written courses on UART and I2C.
If you’d like to apply what you’ve seen in this course, you can read our course on RFID, which uses the SPI link to operate.