2023-10-26 11:34 PM - edited 2023-10-26 11:43 PM
Hi all,
I tried to configure timer 14 to generate interrupt every 500 ms . i am toggling an GPIO to measure delay .
when put a breakpoint interrupt gets triggered but unable to see waveform in logic analyser of GPIO toggling with delay .
My clock frequency is 4 MHZ , desired interval period is 500 ms so PSC is 2000 , ARR is 1000.
Kindly give suggestions
void main()
{
   timer_init();
   HAL_TIM_Base_Start_IT(&htim1);
 
   while(1)
   {
   }
}
void timer_init()
{
    htim1.Instance = TIM14;
	htim1.Init.Prescaler = 2000 - 1;
	htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
	htim1.Init.Period = 1000 - 1;
	htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
	htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
	if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
	{
	    Error_Handler();
	}
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
{
	if(htim->Instance ==  TIM14)
	{
	    /* Peripheral clock enable */
	    __HAL_RCC_TIM14_CLK_ENABLE();
	    /* TIM14 interrupt Init */
	    HAL_NVIC_SetPriority(TIM14_IRQn, 3, 0);
	    HAL_NVIC_EnableIRQ(TIM14_IRQn);
    }
}
void TIM14_IRQHandler()
{
	GPIOB->ODR ^= 1 << 9;
}
Thanks
Narendra C
Solved! Go to Solution.
2023-10-27 1:11 AM
- how do you set the GPIO pin? Read out and check the GPIO registers content
- I wonder how comes you see interrupts in debugger, since you do not enable any interrupt in timer - read out and check TIM_DIER register content
- in the ISR, you have to clear the source of interrupt
Try not to mix Cube/HAL and register-oriented access.
JW
2023-10-27 1:11 AM
- how do you set the GPIO pin? Read out and check the GPIO registers content
- I wonder how comes you see interrupts in debugger, since you do not enable any interrupt in timer - read out and check TIM_DIER register content
- in the ISR, you have to clear the source of interrupt
Try not to mix Cube/HAL and register-oriented access.
JW
2023-10-27 1:48 AM - edited 2023-10-27 2:37 AM
-> Timer started working now after enabling systick timer base
->I have enabled TIMx_ DIER . kindly check the below
-> Now issue is solved after clearing the interrupts
Thank you
