SPI: Serial Peripheral Interface
Serial Peripheral Interface (SPI) is a bus, which provides duplex, synchronous, serial communication between a microcontroller and a peripheral device. Motorola conceived the detailed bus protocol and electrical specifications that we use today. This is a four-wire bus consisting of two wires, which carry the data, one wire carries the clock signal, and one wire for the slave select. Each device is able to receive and send data simultaneously through the separate data wires, hence the term duplex. Each device sends data out and receives data in synchronously with the clock signal.
Applications
Embedded systems such as the PIC controller, 8051, and AVR usually employ this interface for short distance slow communication with a peripheral. It was used for a while in industry, however overtaken with the emergence of faster bus technologies.
The Raspberry Pi has such an interface, which consists of a single master capable of communication with two slave devices.
How it works
As shown in the diagram above, the bus communication is between a master device and a slave device. A single master device connects to multiple slave devices and the data addressed by way of the slave select (SS) pins.
Synchronous Communication
The data transfer is synchronous to the clock pulse generated by the serial clock (SCK). The master device usually produces this clock pulse. The slave devices cannot have any influence on the clock pulse and can only send and receive data synchronously to this pulse, therefore when data is clocked out, new data is clocked in. This type of communication is very advantageous in embedded systems.
Duplex Mode
In full duplex mode a bit of data is sent out by the master and read by the slave and at the same time a bit of data is sent out by the slave and read by the master. This type of data exchange occurs at each clock pulse known as duplex communication.
Master Output, Slave Input (MOSI)
The MOSI pin on the master device connects to the MOSI pin on the slave device. On the master device, MOSI is an output, whilst on the slave device it is an input.
Master Input, Slave Output (MISO)
The MISO pin on the master device connects to the MISO pin on the slave device. On the master device, MISO is an input, whilst on the slave device it is an output.
Slave Select (SS)
Data addressing is by way of slave select (SS) lines. The master device first selects the slave device using this pin, and then sends data out from its MOSI pin. A selected slave device accepts the data that the master device sends out to it.
The Raspberry Pi GPIO interface connector P1 has just such an SPI interface that is capable of selecting two slave devices. The pin names for selecting the slave devices are SPI_CE0, and SPI_CE1. The Raspberry Pi interface usually assumes master mode, and can control a maximum of two slave devices.
This Article Continues...
SPI: Serial Peripheral InterfaceSPI: Serial Peripheral Interface Daisy Chain
Raspberry Pi SPI