For Arduino and related electronics prototyping, we need to know some basic theories which make them working. In our previous articles, we discussed about I²C protocol, some basics on UART and discussed some basic around serial communication. Another phrase you’ll often come to notice is SPI. What is SPI? Full form of SPI is Serial Peripheral Interface. Serial Peripheral Interface is a bus, a synchronous serial communication interface specification primarily used in embedded systems.
What is SPI?
Serial Peripheral Interface bus (SPI) developed by Motorola in the mid 1980s. A common example of application is in liquid crystal displays. SPI also called four-wire serial bus. It operates in full-duplex mode. The circuits communicate according to a master-slave scheme, where the master controls the communication. Several slaves can coexist on the same bus, in such case, the selection of the recipient is done by a dedicated line between the master and the slave called Slave Select (SS). The SPI bus uses four logical signals:
- SCLK – Serial Clock, Clock (generated by the master)
- MOSI – Master Output, Slave Input (generated by the master)
- MISO – Master Input, Slave Output (generated by the slave)
- SS – Slave Select, Active low (generated by the master)
There are other names that are often used:
---
SCK, SCL – Clock (generated by the master)
SDI, DI, SI – serial data IN, MOSI
SDO, SDA, DO, SO – Serial Data OUT, MISO
nCS, CS, nSS, STE, CSN-SS
In the case of the SDI/SDO naming convention, the SDO of the master must be connected to the SDI of the slave and vice versa. To avoid confusion when wiring, it is therefore often recommended to use MISO-MOSI names that avoid ambiguity.
A typical SPI transmission is a simultaneous communication between a master and a slave:
- The master generates the clock and selects the slave with whom he wants to communicate by using the SS signal
- The slave responds to the requests of the master
At each clock stroke the master and the slave exchange a bit. After eight clocks the master transmitted a byte to the slave and vice versa. The speed of the clock is set according to device specific characteristics. The configuration of the SPI is often named in the technical documentation as a number or a couple , where the most significant bit is CPOL (Clock Polarity) and the least significant bit CPHA (Clock Phase).
Advantages and Disadvantages of SPI?
Advantages :
- Full duplex communication
- Greater data flow than an I2C bus
- Flexibility of the number of bits to be transmitted as well as the protocol itself
- Simplicity of the hardware interface
- No possible collision
- Slaves use the master’s clock and therefore do not need their own oscillator
- Sharing a common bus for clock, MISO and MOSI between devices
Disadvantages :
- Engages more pins than a I2C or UART that uses only two
- No addressing possible
- The protocol has no acknowledgment. The master can speak to none without knowing it – no error-checking protocol defined
- No hot swap support