SPI Protocol
► The SPI protocol is a synchronous serial communication interface commonly used. It uses a clock signal to coordinate data transfer between devices.
Clock:
The clock signal ensures that data is transmitted and received at the same rate, preventing errors.
► In SPI, communication happens between a master device and one or more slave devices. The master device controls the clock signal and initiates data transfer. The communication takes place over four pins: MOSI (Master Out Slave In) for data from the master to the slave, MISO (Master In Slave Out) for data from the slave to the master, SCLK (Serial Clock) for synchronization, and optionally, SS (Slave Select) for selecting a specific slave device.
► SPI supports full-duplex communication, meaning data can be sent and received simultaneously. The clock signal defines the timing of data transmission. The master sends data on the MOSI line while the slave sends its response on the MISO line, synchronized by the clock signal.
► SPI offers different configurations such as clock polarity and phase, which determine the timing relationship between the clock and data lines. It has different modes (0 to 3) based on these configurations, allowing flexibility in data transfer.
▪️ Mode 0: Clock Polarity (CPOL) = 0, Clock Phase (CPHA) = 0
The clock is idle low (0) when inactive.
Data is sampled on the leading edge (rising edge) of the clock and shifted on the following (falling edge).
▪️ Mode 1: CPOL = 0, CPHA = 1
The clock is idle low (0) when inactive.
Data is sampled on the trailing edge (falling edge) of the clock and shifted on the leading edge (rising edge).
▪️ Mode 2: CPOL = 1, CPHA = 0
Recommended by LinkedIn
The clock is idle high (1) when inactive.
Data is sampled on the leading edge (falling edge) of the clock and shifted on the following (rising edge).
▪️ Mode 3: CPOL = 1, CPHA = 1
The clock is idle high (1) when inactive.
Data is sampled on the trailing edge (rising edge) of the clock and shifted on the leading edge (falling edge).
► Advantages:
► Disadvantages
► However, SPI requires more pins compared to other protocols like I2C, and it doesn't have built-in mechanisms for addressing or acknowledgment, which can limit its use in complex communication scenarios.