cancel
Showing results for 
Search instead for 
Did you mean: 

Unable achieve delay with timer14 in stm32g030kt6 MCU

Nchun.1
Senior

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 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

- 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

View solution in original post

2 REPLIES 2

- 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

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