HAL UART_IT receive different length commands
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2018-03-06 10:03 AM
I am using the STM32F042F6 with ARM Keil toolchain. I am trying to use UART interrupts to receive commands of different lengths. I have managed to get it some what working using the attached code. I have made a receive buffer, and a counter to keep track of the current character in the buffer. Here is my updated USART_IRQHandler
void USART1_IRQHandler(void)
{ /* USER CODE BEGIN USART1_IRQn 0 */ if ((USART1->ISR & USART_ISR_RXNE) != RESET) { if ((1+rx_buff_pos) < RX_BUFFER_SIZE) { buffer[1+rx_buff_pos++] = USART1->RDR; } } /* USER CODE END USART1_IRQn 0 */ HAL_UART_IRQHandler(&huart1); /* USER CODE BEGIN USART1_IRQn 1 *//* USER CODE END USART1_IRQn 1 */
}In the main loop I then check how much data is available in the buffer by reading value of rx_buf_pos + 1. I then check which command was received by checking the buffer array. This works correctly when all commands are of the same length.
If I do the following
- Send 'on\n' to F04
- Send 'off\n' to F04
Any following commands will not work. Please help me find the cause of this issue so that I can receive different length commands. I have attached my full source code below.
#usart-rx #nvic #hal-usart- Labels:
-
Interrupt
-
UART-USART
