SPI bus protocol and SPI timing diagram detailed

Source: Internet
Author: User
Tags sdo

SPI, is the abbreviation of English serial Peripheral interface, as the name implies is the serial peripheral device interface. SPI, is a high-speed, full-duplex, synchronous communication bus, and on the chip's pin only occupies four lines, saving the chip pin, while the layout of the PCB space saving, convenient, it is for this simple and easy to use features, now more and more chips integrated this communication protocol.
SPI is a ring bus structure, composed of SS (CS), SCK, SDI, SDO, the timing is actually very simple, mainly under the control of SCK, two bidirectional shift registers for data exchange.


Rising edge send, falling edge receive, high first send. When the

Rising Edge arrives, the level on the SDO is sent to the register from the device. When the
falling edge arrives, the level on the SDI will be received in the main device's register.

assumes that the host and slave initialization are ready: and the host's Sbuff=0xaa (10101010), slave sbuff=0x55 (01010101), below will step through the data conditions of the 8 clock cycles of the SPI (assuming the rising edge sends the data).

---------------------------------------------------
Pulse       host Sbuff sbuff SDI SDO
--- ------------------------------------------------
0 00-0   1 0101010 0 1010101 0 0
---------- -----------------------------------------
1 0--1   0 101010x 10101011 0 1
1 1--0 01010100 10101011 0 1
---------------------------------------------------
2 0--1 1010100x 01010110  1 0
2 1--0   1010100 1  0 1010110  1  0
- --------------------------------------------------
3 0--1   0 101001x 1010110 1  0  Span style= "color: #000000;" >1
0  1 0101101  0  1
- --------------------------------------------------
4 0--1   1 010010x 0101101 0  1  Span style= "color: #000000;" >0
1  0 1011010  1 0
---------------------------------------------------
5 0--1 0100101x 10110101 0 1
5 1--0 01001010 10110101 0  1
- --------------------------------------------------
6 0--1   1 001010x 0110101 0  1  Span style= "color: #000000;" >0
1  0 1101010  1  0
- --------------------------------------------------
7 0--1   0 010101x 1101010 1  0  Span style= "color: #000000;" >1
0  1 1010101  0  1
- --------------------------------------------------
8 0--1   0101010x 1010101 0  1  0
8 1--0   0101010 1  10101010  1 0
---------------------------------------------------

This completes the two registers 8-bit exchange, the above 0--1 represents the rising edge, 1--0 represents the falling edge, SDI, SDO relative to the host. According to the above analysis, a complete transmission period is 16 bits, that is, two bytes, because first the host to send commands in the past, and then from the machine based on the host's name to prepare the data, the host in the next 8-bit clock cycle to read the data back.
The SPI bus is Motorola's three-wire synchronous interface, synchronous serial 3-line communication: A clock line sck, a data input line Mosi, a data output line miso, for the CPU and various peripheral devices for full-duplex, synchronous serial communication.   SPI main features are: can send and receive serial data at the same time, can be used as a host or slave, provide frequency programmable clock, send end interrupt sign, write conflict protection, bus competition protection.
The SPI bus has four modes of operation (SP0, SP1, SP2, SP3), the most widely used are SPI0 and SPI3.

in order to exchange data with peripherals, the SPI module can configure the output serial synchronization clock polarity and phase according to the operating requirements of the peripheral, and the clock polarity (CPOL) has no significant impact on the transport protocol. If cpol=0, the idle state of the serial sync clock is low, and if cpol=1, the idle state of the serial sync clock is high. The clock phase (CPHA) can be configured to select one of two different transport protocols for data transfer. If cpha=0, the data is sampled on the first hop edge (up or down) of the serial sync clock, and if cpha=1, the second hop edge (up or down) of the serial synchronization clock is sampled. The SPI Master module communicates with the peripheral tone clock phase and polarity should be consistent.

SPI timing diagram detailed-SPI interface at the moment of output of the first bit of data in mode 0

SPI interface time to output the first bit of data in mode 0

The SPI interface has four different data transmission timings, depending on the combination of the two bits of Cpol and CPHL. The four timings are shown in Figure 1,
The relationship between time series and Cpol and CPHL can also be seen.

Figure 1

The Cpol is used to determine the level at which the SCK clock signal is idle, cpol=0, the idle level is low, cpol=1,

The idle level is high. Cpha is used to determine the sampling time, cpha=0, the first clock in each cycle along the sample,

Cpha=1, the second clock in each cycle is sampled along.

Since I am using a device that works in mode 0 this timing (cpol=0,cpha=0), Figure 1 is simplified to Figure 2,
Focus on the timing of mode 0 only. Figure 2
Let's focus on the first clock cycle of the sck, sampling data at the forefront of the clock (rising edge, first clock edge),
The output data on the back edge of the clock (falling edge, second clock along). First of all, the main device, the main device output (MOSI) outputs data bit1,
At the forefront of the clock is sampled from the device, and at what point does the main device output bit1? The output time of the bit1 is actually before the SCK signal is valid,
ThanThe rising edge of the sck is also half a clock cycle earlier. The output time of the bit1 is not related to the ssel signal. Then look at the slave device,
The input port of the main device miso is also in the forefront of the clock sampling from the device output of the bit1, that from the device and at what time output bit1 it.
from the device is the Ssel immediately after the signal is valid, the output bit1 , although at this time SCK The signal has not yet worked. about the main device above
And the time from the device output bit1 bit, can be verified from Figure 3, 4.
Figure 3
Note in Figure 3, after the CS signal is valid (low level, note the situation after the decline of CS), deliberately using the delay program
Delay for a period of time, and then write to the data register to send the data to see the main device output bit1 (MOSI).
As can be seen, the bit1 (value 1) is the output at the time of the half-clock cycle before the SCK signal is valid (independent of the CS signal),
The rising edge of the first clock cycle of the sck is precisely sampled from the device. Figure 4

In Figure 4, watch the CS and miso signals. We can see that after the CS signal is valid, the bit1 (value 1) is immediately output from the device.

Usually we do 16-bit SPI operations. Figure 5 Records the interface between the first byte and the second byte.
The last digit of the first byte is sampled on the rising edge of the sck, followed by the sck falling edge, and the first bit of the second byte is output from the device.

Introduction to SPI Bus Protocol (interface definition, transmission timing)

First, technical performance
The SPI interface is Motorola's first full-duplex, three-wire synchronous serial Peripheral Interface with master-Slave architecture and support for multi-Slave mode applications, generally supporting only single-Master.
The clock is controlled by master, the data is transmitted in bits at the clock shift pulse, high in front, low in the rear (MSB first), and the SPI interface has 2 unidirectional data lines for full-duplex communication, and the data rates in the current application can be up to a few Mbps.

-------------------------------------------------------
Second, the interface definition
There are 4 signal lines in the SPI interface, namely: Device selection line, clock line, serial output data cable, serial input data cable.

(1) MOSI: Main device data output, from device data input
(2) Miso: Main device data input, from device data output
(3) SCLK: Clock signal, generated by the main device
(4)/ss: From the device enable signal, controlled by the main device

-------------------------------------------------------
III. internal structure
Four, transmission timing The SPI interface in the internal hardware is actually two simple shift registers, the transmitted data is 8 bits, the main device generated from the device enable signal and the shift pulse, the bitwise transmission, high position in front, low post. As shown, the data changes on the falling edge of the SCLK, and the rising edge of a data is stored in the shift register.
the SPI interface does not have a specified flow control, and there is no response mechanism to confirm receipt of the data.   

SPI bus protocol and SPI timing diagram detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.