2024-10-30 04:56 AM
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.
Solved! Go to Solution.
2024-10-30 05:06 AM
Please see the posting tips for how to properly post source code:
Use HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
There should be examples in CubeIDE ?
2024-10-30 05:06 AM
Please see the posting tips for how to properly post source code:
Use HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
There should be examples in CubeIDE ?
2024-10-30 06:05 AM
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.
2024-10-30 06:16 AM
@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?
2024-10-30 06:41 AM
Thank you Andrew,
It works.
Best Regards,