cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401C TIM2 Interrupt

fritz1234
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

   

View solution in original post

4 REPLIES 4

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

JW

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

   

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

Safa_Rajhi
Associate

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