Serial Peripheral Interface (SPI) is a data protocol that is used by microcontrollers for communicating with one or move peripheral devices, quickly and over short distances. SPI can also be used to communicate between two microcontrollers but whatever the situation, there is always one device that is designated as the master device. It is the master device that controls the other device(s).

There are three lines that are common to all of the devices:

Master In Slave Out (MISO)
This is the slave line for sending data to the master.

Master Out Slave In (MOSI)
This is the master line for sending data to the peripherals.

Serial Clock (SCK)
This is the clock pulses, which synchronise the data transmissions that have been generated by the master.

SPI is synchronous, which means that it uses a clock to keep both sides synchronised. The clock is a signal that informs the receiver when to sample the data line. The clock signal is sent along with the data, so the speed is not important. However, there will be an upper limit!

Only the master generates a clock signal. The data is sent from the master to the slave via the MOSI. If the slave needs to respond, it does this via the MISO.

SPI is full-duplex, which means that it can be sending and receiving data at the same time. If you have a circuit that contains more than one slave, then you need to use Slave Select (SS). Using SS tells the slave to wake up and receive/send data. SS can also be used for circuits that contain more than one master. SS is active-low, which means that when it is high, it is disconnected from the SPI bus. When data is going to be sent, SS is made low, activating the slave. When you have finished with the slave, SS is made high.