SPI communication protocol: what does the spi communication interface of the microcontroller mean, and what is the spi interface used for?

To be honest, when I was doing development before, I was most afraid of adjusting spi and iic.

Because the company does not have a logic analyzer, the adjustment is based on experience. If there is a problem, you can't find it. You can only carefully look at the code and blindly adjust it to see if there is a problem with any timing.

Speaking of this, the little friends who are just beginners may ask: What the hell is the single-chip microcomputer spi? What is the spi interface for?

1. What the hell is the MCU spi?

The microcontroller is a programmable microcontroller, and the communication with spi is actually two independent things.

It's just that we can use a single-chip microcomputer to realize spi communication, but the realization of spi communication does not necessarily require a single-chip microcomputer.

We communicate with each other by speaking, and the language of the two people must be the same, for example, both use Mandarin.

The chip communicates with the chip, and they can't speak, so how to transmit information?

It is through the communication bus. There are many kinds of communication buses, such as IIC, SPI, USART, and CAN. Their differences are like Mandarin, English, Korean, and Russian. They are all used to transmit information, but the transmission methods are different .

However, there is a prerequisite for transmitting information, that is, the language must be the same, that is, the communication methods must be the same.

So, spi is a communication method, which is used to transmit information .

Different communication methods have different ways of conveying information.

Spi is a full-duplex, high-speed, synchronous communication bus.

To put it simply, the two of you can talk quickly at the same time, you can tell each other what you want to say, and you can also hear what the other party says at the same time, this is full duplex .

There is another kind called half-duplex, that is, only one of you can speak at the same time, while the other listens, and the other can only speak after finishing speaking.

Obviously, full-duplex transmission of information is more efficient .

Synchronization means that I set a condition for the two of you to talk. For example, if I say start, you can talk, and if I say stop, neither of you can talk.

2. What is the spi interface for?

We people generally rely on our ears and mouth to transmit information, right?

Spi communication transfers information through the interface, see the following figure:

The spi interface has 4 lines, namely CS, SCLK, MOSI, MISO .

SCLK is a synchronous signal , generally controlled by the master.

Since it is communication, it is natural to have an "object", as shown in Figures A and B above.

A is the SPI Master, that is, the master control, such as a single-chip microcomputer, which is generally the role of the master control. The master control is responsible for sending the SCLK synchronization signal to inform the SPI Slave whether data communication is required.

B is SPI Slave, that is, a slave, such as a Flash chip.

CS stands for chip select signal , why use chip select?

Because a SPI Master can communicate with different SPI Slaves.

The SPI Master is controlled by CS. Specifically, which SPI Slave communicates with, and controlling CS to be low means that the SPI Slave is selected.

If you only communicate with one slave device, you can also directly ground the CS series resistor, saving you from having to control it every time.

The full English name of MOSI is Master Output Slave Input, which is generally connected to the data output pin of the master device and the data input pin of the slave device.

The full English name of MISO is Slave Input Master Output, which is generally connected to the data input pin of the master device and the data output pin of the slave device.

In addition, there is a special usage, which is to use only the SPI communication of the two pins SCLK and MOSI.

For example, there is an application of OLED screen in our boundless single-chip microcomputer programming practical project course.

 

The chip select pin CS is directly grounded by hardware because there is only one slave device.

We mainly control the OLED screen to display content, and do not need to read data from OLED, so MISO is not needed either.

In this case, only 2 wires can be used.

Therefore, this kind of protocol needs to be understood in essence, and there is no need to memorize the number of pins connected by rote. Have you learned it?

More practical dry goods for MCU development can go to Wuji MCU programming.

Guess you like

Origin blog.csdn.net/weixin_43982452/article/details/123131338