Skip to main content
Killstreet30
Associate III
February 3, 2023
Question

Timer Interrupt Code Doubt

  • February 3, 2023
  • 3 replies
  • 1749 views

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);

}

}

This topic has been closed for replies.

3 replies

KnarfB
Super User
February 3, 2023

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

hth

KnarfB

Killstreet30
Associate III
February 3, 2023

yes it's enabled.

KnarfB
Super User
February 3, 2023

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

KnarfB
Super User
February 3, 2023

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

Killstreet30
Associate III
February 3, 2023

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?

waclawek.jan
Super User
February 3, 2023

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