Serial Peripheral Interface is a simple interface which enables to communicate microcontroller and peripheral chips or intercommunicate between two or more microcontrollers. Serial Peripheral Interface bus sometimes called four wire interface may be used to interface such chips or devices like: LCD, sensors, memories, ADC, RTC. The range of usage is huge.
SPI Bus uses synchronous protocol, where transmitting and receiving is guided by clock signal generated by master microcontroller. SPI interface allows connecting several SPI devices while master selects each of them with CS (Chip Select) signal – (Underline means that active is LOW).
SPI bus consists of four signal wires:
Master Out Slave In (MOSI),
Master In Slave Out (MISO),
Serial Clock (SCLK or SCK)
Chip Select (CS) for the peripheral.
Some microcontrollers have a dedicated chip select for SPI interfacing called Slave Select (SS).
MOSI signal is generated by master – recipient is Slave. MOSI may also be labeled as SI or SDI.
MISO signals are generated by slave. In some chips you might find labels SO or SDO.
SCLK or SCK are generated by master to synchronize data transfers.
For All Your PCB Need, One-stop PCB Solution Services Appear:
CS (SS) signal is also generated by master to select slave chip or device.
Data transfer is organized by using Shift register in both: master and slave. While master shifts register value out through MOSI line then slave shifts data in to its shift register. If there is full duplex used, then send and receive is performed at the same time:
There also is multiple byte stream mode available with SPI bus interface. In this mode master can shift bytes continuously. Using this type of transfer slave select (SS) must remain low until all stream process continues. For example you can write to memory by sending address bytes and then data in the same stream operation. In this way kilobytes or more can be sent using multiple byte transfer mode.
Some chips have ability when you can connect multiple SPI devices in series and data can be transferred to all devices though other. For instance if you connect three devices to microcontroller in series MCU-A-B-C, then MCU will have to send three bytes of information. The first byte goes to C device, second to B and third byte to A:
Daisy-chain won’t work with devices which support or require multiple bytes operation (memory chips).
For instance AD8403 – 4-Channel Digital Potentiometer can be connected in daisy-chain circuit:
Depending on Clock (SKC) polarity, there may be four operation modes of SPI:
Low clock polarity – when clock is low in idle and toggles in high;
High clock polarity – when clock is high in idle and toggles in low stage;
Clock phase zero – MOSI and MISO outputs are valid on rising edge of clock signal (from low to high);
Clock phase one – MOSI and MISO outputs are valid on falling edge of SCK signal (high to low)