cancel
Showing results for 
Search instead for 
Did you mean: 

how to enable uart interrupt

Ndemir
Associate II

Hello,
I want to activate UART1 interrupt directly through code in STM32CubeIDE, without using the .ioc file. UART1 is already active, so I just need to add the necessary lines to enable the interrupt.

In the stm32wbxx_it.c file, I defined the interrupt handler as follows:

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 */
}

In the stm32wbxx_it.h library, I declared the prototype as void USART1_IRQHandler(void);. However, I am still not able to receive data using the HAL_UART_Receive_IT function.

1 ACCEPTED SOLUTION

Accepted Solutions

Please see the posting tips for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

Use HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()

There should be examples in CubeIDE ?

View solution in original post

4 REPLIES 4

Please see the posting tips for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

Use HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()

There should be examples in CubeIDE ?

Ndemir
Associate II

Thank you for your information. I will consider when I post.

I add this in "stm32wbxx_it.h".

void USART1_IRQHandler(void);


I add this in "stm32wbxx_it.c".

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 */
}

Where should I use HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() functions. I compare my code with the other examples and I didn't find any difference.


@Ndemir wrote:

Where should I use HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() functions.


Wherever it makes sense to enable the interrupt - somewhere before you call the HAL_UART_Receive_IT() function

 


@Ndemir wrote:

I compare my code with the other examples and I didn't find any difference.


Were they examples of using interrupts?

Ndemir
Associate II

Thank you Andrew,

It works.
Best Regards,