2024-03-25 03:27 PM - last edited on 2024-06-11 08:08 AM by Amel NASRI
Hello,
I try to use a TIM2 Interrupt to toggle a LED. I use a STM32F401C controller.
If I toggle the LED inside the while loop with delay, it works fine.
while (1)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_15);
HAL_Delay(1000);
}
But there is no interrupt for TIM2.
I attached the CubeMX ioc file. Have I forgotten something to parmatrize?
Solved! Go to Solution.
2024-03-26 01:28 PM - edited 2024-03-26 01:43 PM
I forgot to call
TIM2-> DIER = TIM_DIER_UIE;
Is there a HAL Function to set TIM->DIER ?
These are the values of the peripheral TIM2 and NVIC. Timer 2 is counting.
2024-03-25 04:55 PM
Read out and check/post content of TIM and relevant GPIO registers.
JW
2024-03-26 01:28 PM - edited 2024-03-26 01:43 PM
I forgot to call
TIM2-> DIER = TIM_DIER_UIE;
Is there a HAL Function to set TIM->DIER ?
These are the values of the peripheral TIM2 and NVIC. Timer 2 is counting.
2024-03-27 04:52 AM
Thanks for coming back with the solution.
> Is there a HAL Function to set TIM->DIER ?
I don't know, I don't use Cube/HAL. Probably there's a macro. Cube/HAL is open source.
However, I believe, under Cube/HAL you are not supposed to set TIMx_DIER directly; you are supposed to call some of the HAL_xxx_Start_IT() functions (or something like that) which do this for you. Read the HAL/Cube documentation (which is mostly the comments to functions which you can see also in the source code).
JW
2024-07-25 03:36 AM