STM32cubeMX USART operation in interrupt mode

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hey. I require to read multiple bytes using USART ( 3 bytes of MIDI data ). I have generated my project using STM32cubeMX and using USART generated functions. I do not need to transmit anything, I only require to receive 3 bytes and then process the bytes ( processing will come later) at this point, I just want to make sure that I properly receive 3 bytes . I have few questions regarding how USART works and hopefully someone with a little bit more knowledge can help me out.

1. What is the difference between void USART1_IRQHandler(void) and void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart1),?

I am using function HAL_UART_Receive_IT to receive 3 bytes and I am calling it like that :

uint8_t aRxBuffer[3];
HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, sizeof(aRxBuffer))

I have created an RxBuffer with a size of 3 to store 3 bytes of data. I assume that when there is some data to be received ( MIDI instrument key pressed), the RXcallback or irqhandler is called where I manually set the flag to start receiving bytes.

C:
void USART1_IRQHandler(void)
{
  /* USER CODE BEGIN USART1_IRQn 0 */
  got_byte = 1;


  /* USER CODE END USART1_IRQn 0 */
  HAL_UART_IRQHandler(&huart1);
  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */
}


The code in my main is :

C:
if(HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, sizeof(aRxBuffer)) != HAL_OK)
            Error_Handler();
  while (1)
  {
      if(got_byte == 1)// RECEIVE ONE BYTE AND STORE IT INTO byte[] BUFFER
      {      
        byte[i++]=aRxBuffer[i];
        got_byte = 0;
      }
  }
So as you can see, Im checking whether the flag has been set and then I fill the buffer that I have crated byte[] with the data from RxBuffer. However I am concerned whether I am understanding the USART correctly?

Do i need to set the flag USART1_IRQHandler(void) or void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart1)?
 
Last edited:
Top