title: STM32 HAL USART receive by interrupt
body: <p>I have some trouble to receive data over the USART. What I actually want to achieve ist, that I can receive a command over USART with no specific length (only a maximum possible length). So I use the interrupt routine to check each character received, but I somehow still cannot achieve what I want. The routine is called each time I receive a new character, but somehow HAL_UART_Receive_IT(&amp;huart1,rx_data,buff_size_rx) does not upgrade in realtime, then I don't see the received character when I check rx_data[pointer], but a few time later it is in the rx_data buffer.</p>
  
  <p>What I have so far:</p>
  
  <pre class="lang-c prettyprint-override"><code>int pointer =0;
  
  ...
  
  void USART1_IRQHandler(void)
  {
    /* USER CODE BEGIN USART1_IRQn 0 */
      if ( USART1-&gt;ISR &amp; UART_IT_TXE) {
  
      }
  
      if ( USART1-&gt;ISR &amp; UART_IT_RXNE) {
          HAL_UART_Receive_IT(&amp;huart1,rx_data,buff_size_rx);
          if(rx_data[pointer]=='\0') {
                pointer=0;
                readCommand(rx_data);
                clearBuffer(rx_data,buff_size_rx);
          } else {
            pointer++;
            if(pointer&gt;=buff_size_rx) {
                pointer=0;
            }
          }
      }
      /* USER CODE END USART1_IRQn 0 */
      HAL_UART_IRQHandler(&amp;huart1);
      /* USER CODE BEGIN USART1_IRQn 1 */
  
  
  
    /* USER CODE END USART1_IRQn 1 */
  }
  </code></pre>