Skip to main content
Associate II
Oct 30, 2024 11:56 AM UTC
Solved

how to enable uart interrupt

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.

This topic has been closed for replies.
Andrew Neil
Andrew NeilBest answer
Super User
Oct 30, 2024 12:06 PM UTC

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 ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.

4 replies

Andrew Neil
Andrew NeilBest answer
Super User
Oct 30, 2024 12:06 PM UTC

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 ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NdemirAuthor
Associate II
Oct 30, 2024 1:05 PM UTC

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.

Andrew Neil
Super User
Oct 30, 2024 1:16 PM UTC

@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?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
NdemirAuthor
Associate II
Oct 30, 2024 1:41 PM UTC

Thank you Andrew,

It works.
Best Regards,