SPI communication details, spi communication
SPI data transmission and receiving Mechanism
1 SPI Overview
SPI is a ring bus structure that operates in the master-slave mode. This mode usually has one master device and one or more slave devices and requires at least four lines (during Unidirectional transmission, the three lines can also be used), which is composed of ss (cs), sck, sdi, and sdo. the time sequence is actually very simple, mainly under the control of sck, two two-way shift registers are used for data exchange, allowing the MCU to adopt full-duplex synchronous serial mode. It only specifies how data is transmitted for each frame, and does not introduce the composition of the frame structure.
2 SPI features
2.1 master-slave mode
The communication between two SPI devices must be controlled by the master device. A master device can control multiple slave devices by providing Clock and SlaveSelect/ss, the SPI protocol also specifies that the ClockMaster device of the slave device is provided to the slave device through the SCK pin. The slave device itself cannot generate or control the Clock. If no Clock is provided, the slave device cannot work normally.
2.2 Data Transmission in synchronous Mode
The Master device generates the corresponding Clock pulse (ClockPulse) based on the data to be exchanged. The Clock Pulse forms the Clock Signal (Clock Signal), and the Clock Signal passes the Clock polarity (CPOL) the Clock Phase (CPHA) controls when data is exchanged between the two SPI devices and when the received data is docked for sampling to ensure that the data is transmitted synchronously between the two devices.
2.3 Data Exchange)
Data transmission between SPI devices is also called data exchange because the SPI protocol stipulates that an SPI device cannot act only as a "Transmitter" or "Receiver" during data communication) ". In each Clock cycle, the SPI device sends and receives a bit of data, which is equivalent to a bit of data being exchanged. To receive the control signal sent from the Master, a slave device must be able to be accessed by the Master device before that ). Therefore, the Master device must first use SS/CSpin to select the target device from the source device. During data transmission, the data received each time must be sampled before the next data transmission.