SPI is a very common development board interface like the IIC interface, but compared with the IIC, SPI has designed a binary stream interaction mode, with a faster transmission speed, it can exchange messages between any two embedded devices, and the ELF 1 development board is also connected to a six-axis accelerometer through the SPI interface.
The six-axis accelerometer uses the SPI bus for setup and data transmission. The communication principle of SPI is very simple, it works in a master-slave mode, this mode usually has a master and one or more slaves, and requires at least 4 wires, in fact 3 can also be used (when transmitting in one direction). It is also common to all SPI-based devices, they are MOSI (Master-Slave In), MISO (Master-Slave Out), SCLK (Clock), CS (Chip Select). The clock signal is controlled only by the master device and is used for clock synchronization. In the master-multi-slave mode, each slave has an independent CS signal line, and if you want to communicate with a specific slave, you can pull the corresponding CS (NSS in the figure below) signal line low. The SPI interface is transceivingDual full-work serial transmission,When the master sends one bit to the slave, the slave also sends one bit to the master. The situation of one master and many slaves is shown in the following figure:
SPI has4 ways of workingClock polarity (CPOL) and phase (CPHA) work together to determine how data is read, such as whether the rising or falling edge of the signal is read, and a mode can be set for a chip select signal.
How SPIs work is as follows:
spiBusmode
The SPI timing diagram is shown below
CPOL is used to determine the level at which the SCLK is idle:
cpol=0, low at idle;cpol=1, high at idle;
The CPHA is used to determine the time of sampling:
cpha=0, the first clock edge of each cycle is sampled;CPA=1, the second clock edge of each cycle is sampled.
About the SPI interface is briefly introduced here, I hope it can be helpful to the friends in front of the screen.