[SPI] Introduction to SPI communication protocol

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 :
    1. Support full duplex operation
    2. easy to use
    3. Higher data transfer rate
  • Disadvantages :
    1. Need to occupy more lines of the master (each slave needs a chip select line)
    2. No flow control specified
    3. 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.
Insert picture description here

  1. MOSI : master device data output, slave device data input
  2. MISO : Master device data input, slave device data output
  3. SCLK : clock signal, generated by the master device
  4. 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

Insert picture description here

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 :
    Insert picture description here
    Insert picture description here
  • Read timing :
    Insert picture description here
    Insert picture description here

(Note: The first screenshot is the timing introduced by the datasheet, and the second screenshot is the timing actually captured by the logic analyzer)

5. Reference materials

  1. 《BMI160 DataSheet.pdf》
  2. "Playing with STM32-F429 Challenger with Zero Dead Angle.pdf"

Guess you like

Origin blog.csdn.net/ZHONGCAI0901/article/details/110452411
SPI