cancel
Showing results for 
Search instead for 
Did you mean: 

Timer interrupt not working in STM32G030x

arjun.binu
Associate III

We were using TIM16 to count and monitor if a button is pressed for more than 2 seconds. If pressed for more than 2 seconds, an interrupt will be generated and a flag will be set. This was successfully implemented when used as shown below:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {

if (&htim16 == htim) {

__HAL_TIM_CLEAR_FLAG(&htim16, TIM_IT_UPDATE);

__HAL_TIM_DISABLE_IT(&htim16, TIM_IT_UPDATE);

if (device_C.is_in_use == NO) {

device_C.is_in_use = YES;

device_C.in_use_state = DEV_INIT;

}

}

}

After incorporating some other changes, now the timer stops generating intterupts(it seems as if the counter does not overflow). The followings were the changes being made.

0693W00000aHm2mQAC.png 

Are the above changes having any significant effect?

Also i have tried to enable the IRQ forcefully by using HAL_NVIC_EnableIRQ(TIM16_IRQn); in the HAL_GPIO_EXTI_Falling_Callback() and vice versa (HAL_NVIC_DisableIRQ(TIM16_IRQn); in the HAL_GPIO_EXTI_Rising_Callback()).

I noticed that it entered interrupt was Timer counter flow interrupt was generated once.But it is not working as it worked earlier for us.

Attaching the CubeMX report here for reference.

1 ACCEPTED SOLUTION

Accepted Solutions
arjun.binu
Associate III

There were mistakes while configuring the timer. Now it is working fine.

Thanks @S.Ma​ for your suggestion on the above implementation of key debounce.

View solution in original post

2 REPLIES 2
S.Ma
Principal

Well, on STM32C0316 brisk demo, there is a simple implementation of key debounce with optional "hot key" pressed for 5 seconds, to make special action, using a RAM counter hooked on systick 1 msec interrupt.

Due to small pincount package, the buttons use a single input ADC pin where each button is mapped as voltage range. Otherwise the code can be recycled simply for a digital keyboard.

There is also a delay function using timer if necessary.

You can dig from brisk.c UserKey_50ms();

arjun.binu
Associate III

There were mistakes while configuring the timer. Now it is working fine.

Thanks @S.Ma​ for your suggestion on the above implementation of key debounce.