Article Directory
related articles
1. "Introduction to SPI Communication Protocol"
2. "Use of STM32 SPI Peripherals"
3. "[IMU] Analysis and Use of BMI160 Driver"
1. Introduction to SPI
SPI protocol is a communication protocol (Serial Peripheral Interface
)proposed by Motorola, that is, serial peripheral device interface, which is a high-speed full-duplex communication bus. It is widely used between ADC, LCD and other devices and MCU, where higher communication speed is required.
- Advantages :
- Support full duplex operation
- easy to use
- Higher data transfer rate
- Disadvantages :
- Need to occupy more lines of the master (each slave needs a chip select line)
- No flow control specified
- There is no response mechanism to confirm whether data is received
2. Introduction to SPI hardware connection
Two SPI devices communicate must be borne by the master device (Master) is controlled from the device (the Slave) . The master device can control multiple slave devices by providing a clock signal and performing chip selection on the slave device. The slave device itself does not generate a clock signal, and its clock signal is provided by the master device.
- MOSI : master device data output, slave device data input
- MISO : Master device data input, slave device data output
- SCLK : clock signal, generated by the master device
- CS : slave device enable signal, controlled by the master device
3. Introduction to SPI communication mode
SPI communication has 4 different modes, which are generally configured through CPOL (clock polarity) and CPHA (clock phase) . as follows:
SPI mode | CPOL | CPHA | Idle SCK clock | Sampling moment |
---|---|---|---|---|
0 | 0 | 0 | Low level | Odd edge |
1 | 0 | 1 | Low level | Even edge |
2 | 1 | 0 | High level | Odd edge |
3 | 1 | 1 | High level | Even edge |
4. SPI read and write timing
Here, the SPI read and write timing is introduced through an example of an IMU ( BMI160 ) with an SPI interface , which uses mode 3 ( CPOL=1 CPHA=1
) by default .
- Write timing :
- Read timing :
(Note: The first screenshot is the timing introduced by the datasheet, and the second screenshot is the timing actually captured by the logic analyzer)