Skip to main content
Visitor II
March 25, 2024
Solved

STM32F401C TIM2 Interrupt

  • March 25, 2024
  • 2 replies
  • 1883 views

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?

    This topic has been closed for replies.
    Best answer by fritz1234

    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.

     

    nvic1.PNG

    nvic2.PNG

    tim2.PNG

    2 replies

    Super User
    March 25, 2024

    Read out and check/post content of TIM and relevant GPIO registers.

    JW

    fritz1234AuthorAnswer
    Visitor II
    March 26, 2024

    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.

     

    nvic1.PNG

    nvic2.PNG

    tim2.PNG

    Super User
    March 27, 2024

    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

    Visitor II
    July 25, 2024

    Hi when i try to open ur MX file it returns this i probably need to download the latest version but i dont want to the current one is working just fine . can u screenshot ur code for me i am working on the same thing but with a nucleo l152RE and ur work might help me figure it out