cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 timer interrupts with HAL_TIM_PWM_PulseFinishedCallback and HAL_TIM_PeriodElapsedCallback does not work as intended

MKanc.1
Associate III

I am trying to do a blink example for testing using built-in LED on bluepill. Unlike regular delay and period interrupts, i want to try a custom-duty blink, in which i want 3s on and 2s off, a total of 5s period.

in main:

 HAL_TIM_Base_Start_IT(&htim1);

 HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);

callbacks:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

   HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);

}

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef * htim)

{

   HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);

}

does not work as intended. It just blinks once per period rapidly which is hard to catch. If i disable any of these callbacks, it blinks with period. What am i doing wrong?

2 REPLIES 2

> If i disable any of these callbacks, it blinks with period.

This doesn't make much sense - if only one of the interrupts work, there should be nothing which would switch off or switch on the LED, so it would remain lit/dark.

Read out and check/post content of TIM registers.

How is the PC13 pin set up in GPIO?

The PC13 pin is connected only to the LED, or is there any other connection?

JW

MKanc.1
Associate III

Sorry, forgot to say, if i use single interrupt, i use toggling to blink over time.

PC13 is definitely LED and nothing else is connected.

I am using timer 1.