cancel
Showing results for 
Search instead for 
Did you mean: 

TIM16 incorrect, random period

avidroneg
Associate

This is for an STM32F303.

I've reduced my MX configuration down as much as possible so that it only has SWD and a button on GPIO PA8 configured and the incorrect behaviour still occurs. The intent is for PA8 EXTI falling edge to start a timer, and for that timer to in turn interrupt on expiry. I do get an interrupt (for both EXTI and the timer), but the duration of the timer is always wrong (sometimes instant, sometimes quite slow), and when on interrupt I check instance->CNT it is always a random value.

avidroneg_0-1759763131044.png

avidroneg_1-1759763166203.png

Following https://community.st.com/t5/stm32cubeide-mcus/hal-tim-periodelapsedcallback-firing-very-prematurely/m-p/588486 I am issuing

hbuttonDebounceTimer->Instance->SR &= ~TIM_SR_UIF;

during USER CODE 2 (after init, before the main loop), and it has no effect.

My ISRs look like

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
    if (htim == buttonDebounceTimer) {
        HAL_TIM_Base_Stop_IT(htim);
    }
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
    switch (GPIO_Pin) {
    case nBUTTON_Pin:
        HAL_TIM_Base_Start_IT(buttonDebounceTimer);
        return;
    }
}
0 REPLIES 0