cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Interrupt Code Doubt

Killstreet30
Associate III

Hello. I used to use the following code for starting a timer interrupt and used to set up the pre scalar and counter such a way I get the desired frequency but now this code is not working. My LED doesn't blink at all. I just wanted to check if the code is wrong or iff my hardware has some problem.

  HAL_TIM_Base_Start_IT(&htim2);

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){

if(htim->Instance == TIM2){

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);

}

}

7 REPLIES 7
KnarfB
Principal III

Have you enabled that timer interrupt in the chip configuration tool?

hth

KnarfB

yes it's enabled.

What chip?

Two ways:

  • check/dump/post the relevant timer registers
  • place a breakpoint in the native TIM2 IRQ handler in the _it.c source file and step into the HAL code

hth

KnarfB

NUCLEO - L476RG

the code was working perfectly a week back today it just doesn't seem to work so I'm not able to understand what went wrong cause there has been no change.

KnarfB
Principal III

Other interupts, eating up the CPU? Somehow disabled interrupts? Look at the registers, they do not lie.

or: roll-back your code, use git early and often https://youtu.be/hwP7WQkmECE

hth

KnarfB

no other interrupts are enabled and I restored the version yet I don't know it just doesn't work. I updated my STM IDE version. does that make a difference?

Check whether the real ISR is called, not the callback, to exclude Cube/HAL issues.

Read out and check/post content of TIM and NVIC registers.

Generic guideline for "interrupt does not fire" here.

JW