cancel
Showing results for 
Search instead for 
Did you mean: 

Differentiating between multiple uart interrupts

SA.17
Associate III

Hi,

I am using STM32L07xxx

I want to use USART4 and USART 5

So i generated code using STM32CUBEMX

Below is generated code for interrupt

void USART4_5_IRQHandler(void)
{
  /* USER CODE BEGIN USART4_5_IRQn 0 */
 
  /* USER CODE END USART4_5_IRQn 0 */
  HAL_UART_IRQHandler(&huart4);
  HAL_UART_IRQHandler(&huart5);
  /* USER CODE BEGIN USART4_5_IRQn 1 */
 
  /* USER CODE END USART4_5_IRQn 1 */
}

When interrupt happens , how i find which uart has generated an interrrupt between uart 4 and uart 5 ?

3 REPLIES 3

Normally, you would read out both UART status registers and act upon bits in them.

Cube is supposed to do this for you in HAL_UART_IRQHandler() (look at that function what does it do - Cube is open source) and then calls your callbacks passing a particular handler, if there is some event for the UART associated with that handler.

JW

Thanks,

handler is calling a callback

HAL_UARTEx_WakeupCallback(huart);

is there any flag for telling which uart ?

You can determine the uart using the instance handle, and the address of the uart peripheral therein.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..