TIM3 periodElapsedCallback never called
In my code, after setting an on-board LED, the timer is started like this.
__HAL_TIM_SET_COUNTER(&htim3, 0);
while(HAL_TIM_Base_Start_IT(&htim3) != HAL_BUSY);In debugging mode, I saw that the CNT register was in fact incrementing, however in would always rollover and would never trigger this callback function:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance == TIM3)
{
while(HAL_TIM_Base_Stop_IT(htim) != HAL_BUSY);
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, RESET);
}
}I saw on another forum post that someone suggested to put that code in stm32l0xx.c in the function TIM3_IRQHandler(). However when I did that, I found that the function was called instantly after HAL_TIM_Base_Start_IT(&htim3).
What is going on here? I opened a new project with the EXACT same settings for timer 3, and it worked perfectly. This project has become far too massive to move everything over to a new project without a lot of headache. I would prefer to find out how to solve this in the project I am currently working on. Here is the cubeMX configuration:
static void MX_TIM3_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim3.Instance = TIM3;
htim3.Init.Prescaler = 2047;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 7811;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}