cancel
Showing results for 
Search instead for 
Did you mean: 

Timer interrupting on MCU reset

Nico3
Associate III

Hello I have set the timer7 for 1 minute interrupt. It is working at every minute as expected. 

But the interrupt is also triggered as MCU is reset. I have set global counter for increment in timer7 callback. As soon MCU is reset , Timer7 callback is called and counter is incremented. Please suggest why it is happening.

static void MX_TIM7_Init(void)
{

/* USER CODE BEGIN TIM7_Init 0 */

/* USER CODE END TIM7_Init 0 */

TIM_MasterConfigTypeDef sMasterConfig = {0};

/* USER CODE BEGIN TIM7_Init 1 */

/* USER CODE END TIM7_Init 1 */
htim7.Instance = TIM7;
htim7.Init.Prescaler = 65400;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
htim7.Init.Period = 44035;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}

}

//**********************************

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
 
str_flag = str_flag + 1;
 
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Before you start the timer and enable interrupts, generate an update event and clear the UE bit. Timers being triggered immediately can be due to the ARR register being preloaded.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

Before you start the timer and enable interrupts, generate an update event and clear the UE bit. Timers being triggered immediately can be due to the ARR register being preloaded.

If you feel a post has answered your question, please click "Accept as Solution".
Nico3
Associate III

thanks..