Skip to main content
MKanc.1
Associate III
April 28, 2021
Question

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

  • April 28, 2021
  • 2 replies
  • 989 views

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?

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    April 29, 2021

    > 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
    MKanc.1Author
    Associate III
    April 29, 2021

    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.