Skip to main content
Nchun.1
Associate III
October 27, 2023
Solved

Unable achieve delay with timer14 in stm32g030kt6 MCU

  • October 27, 2023
  • 1 reply
  • 1062 views

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;
}

 

 

 

@Tesla DeLorean , @TDK 

 

Thanks 

Narendra C 

 

 

This topic has been closed for replies.
Best answer by waclawek.jan

- 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

1 reply

waclawek.jan
waclawek.janBest answer
Super User
October 27, 2023

- 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

Nchun.1
Nchun.1Author
Associate III
October 27, 2023

Hi @waclawek.jan 

-> Timer started working now after enabling systick timer base

->I have enabled TIMx_ DIER . kindly check the below

Nchun1_0-1698396327273.png

-> Now issue is solved after clearing the interrupts 

Nchun1_0-1698399384307.png

 

Thank you