What is SPI?
UART
The most basic way to communicate between two devices is UART.
​
UART connects two devices together using 2 wires, one used for transmitting and one for receiving.
​
​

This is very reliable and variations of it are used in many other comms protocols such as USB, RS232 & RS485.
UART has a few downsides:
-
It can only connect two devices together.
-
It requires setting up the clock speed on both devices to synchronize the data.
I2C
The next common solution is to use I2C.
This comms protocol uses only 2 wires:
SDA: This is the Serial Data Line and is used for both transmitting and receiving data.
SCL: This is the Serial Clock Line and is used to start/stop and control the direction of messages.

This communication method requires each device to have an address.
​
It's data is packaged in a message with the start of the message having the address, followed by the data. This is how a message is packaged:

I2C also has a few downsides:
-
It is much slower than UART as it only has 1 data line and requires data in strict packages.
-
It requires every device to be configured to have an address.
-
It is more complex than UART.
SPI
SPI, or Serial Peripheral Interface, is a communications method that delivers the fast speeds of UART, with the expandability of I2C.
​
It uses 4 wires:
-
MOSI: Master Out Slave In. This is used for transmitting data from the Master to the Slave devices.
-
MISO: Master In Slave Out. This is used for receiving data to the Master from the Slave devices.
-
SCK: SPI Clock. This keeps the devices synchronized.
-
CS: Chip Select. This is a dedicated output per slave device to start communication.

As SPI is a bus, all the devices share the same transmit (MOSI), recieve (MISO) and clock (SCK) lines but require an independant Chip Select (CS) lines.
Since SPI uses separate receive, transmit and clock lines, it can communicate data much faster than I2C typically operating in the MHz range. It also is able to send more data, as it doesn't package data into standard messages.
​
SPI has a few main downsides:
-
It uses a lot of wires.
-
It can't communicate over long distances.