How to receive and respond to USART string commands
This article will explain in detail how to receive and respond to USART string commands. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
The application of USART1 interrupt service function (void USART1_IRQHandler (void)).
The message is sent to the stm32 USART1 serial port through the serial port helper, and the start and stop character of the message is defined in the USART1_IRQHandler function to get the content of the input message.
# define CMD_SIZE 256 char cmd [CMD _ SIZE]; / / store received message string int cmd_point=0; / / message character subscript void USART1_IRQHandler (void) {U8 res; if (USART_GetITStatus (USART1, USART_IT_RXNE)! = RESET) / / receive interrupt {res=USART_ReceiveData (USART1); / / read received data if (res==' >') {cmd_point=0 Memset (cmd,0,CMD_SIZE); / / clear} else {cmd_point++; if (res==0x0d) {/ / end additional bit return USART1_printf ("cmd:%s\ n\ r", cmd); cmd_point=0;} else {cmd [cmd _ point-1] = res }
On how to receive and respond to USART string commands is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.