I saw the method of serial port receiving on the avr forum. It was helpful for the project, so I recorded it.
Thanks to AVRBBS for providing the method
static unsigned char i; //Define a static variable to record which byte is received. switch (i) { case:0 if (udr == 0xAA) //Receive the first data and determine whether it is the 0XAA start byte. i = i + 1; //Synchronization successful, increase variable i and proceed to the next step. break; case:1 In this step, get the length of the first symbol and save it in the receiving array you defined. It will be used when receiving data later. case:2 Receive command bytes and store them into the array. The above is a general process for your reference and study. The specific procedures below need to be completed by yourself. case:7 Determine the frame stop bit (0x55) and whether the previous bit check is correct. If both are successful, do the following two things: 1. Take certain actions according to your situation, or put a certain mark to indicate that you have received it. 2. Remember to reset the variable i = 0.
Previous article:Serial port receiving ideas
Next article:Defining data and command input methods in AVR
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Proteus emulation of micropython method
- What is the principle of the reading pen? How does it improve the accuracy of reading?
- Where is the lucky star? ——"Keysight Technology Double 11 Instrument Flash Sale"
- My design is equivalent to changing the original manual control to automatic control. The overall design idea is as follows, but at this stage it is still...
- Play with the Internet of Things and make a smart greenhouse model!
- I used the AD18STM32 library to import the chip, but the chip pins are incomplete
- MSP430 interrupt nesting mechanism
- IIC Protocol Analysis
- Award Ceremony | How do you purchase or select electronic components?
- MSP430 MCU Development Record (13)