cancel
Showing results for 
Search instead for 
Did you mean: 

HAL UART_IT receive different length commands

Tom Eaton
Associate II
Posted on March 06, 2018 at 19:03

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

  1. Send 'on\n' to F04
  2. 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
0 REPLIES 0