Click on "Uncle Wheat" above and select "Top/Star Public Account"
Welfare dry goods, delivered as soon as possible
The flexibility of the protocol is considered in the communication design, and the protocol is often designed as "indefinite length".
An example is as follows: the communication protocol frame of the Ruimi LoRa terminal.
If a system receives the above-mentioned "indefinite length" protocol frame, there will be a challenge - how to receive and parse it efficiently.
In order to simplify the system design, we strongly recommend that you use the "state machine" to parse the UART data frame, and put the parsing work in the ISR (interrupt service routine) to complete, only when the last byte (0x0D) is received, then the entire The data frame is submitted to the process for processing.
The principle of the parsing state machine is shown in the following figure:
So is it time for the ISR to process this state machine? The answer is: so easy! Because it has only 3 actions, the computation is very small:
Compare the received data -> update the state variable -> store the received data, there are only 3 statements in the C language, and the translation into machine instructions does not exceed 10.
The code listing is as follows:
Today's article is here, the article is not long, the design idea is very important, I hope to help you.
Original address: https://blog.csdn.net/jiangjunjie_2005/article/details/50619884
The copyright belongs to the original author, if there is any infringement, please contact to delete it.
—— The End ——
Recommended in the past
46 million units sold! The Road to Raspberry Pi
Good tool, don't hide it! Introduce a tool to improve efficiency
This c language skill refreshed my understanding of structures!
You can never imagine that C language can play like this!
Good project, don't keep it private! Open source wheels for microcontroller development
MCU development never uses data structures?
Click on the card above to follow me
Everything you ordered looks good , I take it seriously as I like it