cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

STM32F103RE combined UART receive via interrupt

AAnju.1
Associate

Hi,I'am using STM32F103RE. i have enable 3 usart for GSM modem(USART1), Debug(UART4) and GPS(UART2). now i need to collect data under interrupt routing. it should be something like this, this is for ATMEL:D

ISR(USART0_TX_vect)
{
   byte  myChar= UDR0 ;
}

i need to handle interrupt individually. i used this

HAL_UART_Receive_IT(&huart1,(uint8_t *)buff,10); 

but i have to call this everytime when i need read the receiver pin

i'am using STMcubeMX and KeiluVision

Thank in advance

2 REPLIES 2
KnarfB
Principal III

If you generate the code using STM32CubeMX, check the USARTx global interrupt in the NVIC settings tab of all three UARTs. Then, the re-generated code has three interrupt handlers in stm32f1xx_it.c. They look like

void USART1_IRQHandler(void)
{
  /* USER CODE BEGIN USART1_IRQn 0 */
 
  /* USER CODE END USART1_IRQn 0 */
  HAL_UART_IRQHandler(&huart1);
  /* USER CODE BEGIN USART1_IRQn 1 */
 
  /* USER CODE END USART1_IRQn 1 */
}

etc.. You can see that the HAL handles the interrupt. HAL_UART_IRQHandler analyses the various interrupt sources and finally calls so-called callback functions. You define the callback functions you need e.g. in main.c like ordinary functions:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{ 
  if(huart->Instance==USART1) {
     ...  // read out buff
  }
   ...
}

The callback naming must exactly match. See the comments and source code in stm32f1xx_hal_uart.c.

The pure HAL mechanism has some overhead and does not fit advanced use cases. But it should work okay for 3 UARTs.

Note that NMEA telegram parsing has been discussed here quite often. Using a char by char rx interrupt seems adequate. For more advanced UART handling see https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

TDK
Guru

If you want to handle individual bytes, you will need to call HAL_UART_Receive_IT with a buffer of length 1. HAL isn't set up to handle receiving individual bytes.

You could also roll your own solution checking for the RXNE bit in the ISR.

If you feel a post has answered your question, please click "Accept as Solution".