Senior
January 12, 2022
Solved
Timer interrupt and GPIO toggling
- January 12, 2022
- 3 replies
- 2625 views
hey there
I have a STM32f030k6t6 which I wish to set a timer(TIM16 in this case) and each time timer interrupts, a GPIO pin toggles. I attach the clock configuration.
and here is my tim16 config
htim16.Instance = TIM16;
htim16.Init.Prescaler = 10;
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
htim16.Init.Period = 44236;
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim16.Init.RepetitionCounter = 0;
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
{
Error_Handler();
}and this is start of timer
if(HAL_TIM_Base_Start_IT(&htim16)!=HAL_OK)//
{
Error_Handler();
}and finally timer interrupt and GPIO toggling
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM16)
{
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_3);
}
}now funny thing is that as I have set timer to interrupt every 10ms, but when I use oscilloscope, each timer interrupt is shown to be 4ms.
so why is that?
