Skip to main content
AKozarzewski
Associate II
June 19, 2023
Solved

TIM16 never calls interrupt handler in STM32WLE4

Hi

I've configured automatically from IOC timer TIM16 as it is more basic timer and I need basic funcionality: do some action on timer interrupt, I use HAL driver, but handler is never called.

initialisation is simple:

void MX_TIM16_Init(void)
{

/* USER CODE BEGIN TIM16_Init 0 */

/* USER CODE END TIM16_Init 0 */

/* USER CODE BEGIN TIM16_Init 1 */

/* USER CODE END TIM16_Init 1 */
htim16.Instance = TIM16;
htim16.Init.Prescaler = 511;
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
htim16.Init.Period = 50000;
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim16.Init.RepetitionCounter = 0;
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM16_Init 2 */

/* USER CODE END TIM16_Init 2 */

}

Timer is running , I can see it's changing value when read. It's set to reload periodicaly, it does that,  interrupt is enabled, given higher priority than others, just in case. Vector table is properly initialised. But interrupt handler never is called. What to check, any ideas?

    This topic has been closed for replies.
    Bob S
    Bob SBest answer
    Super User
    June 19, 2023

    Did you enable the TIM16 interrupt in the NVIC.  In CubeMX, select TIM16 then click on the "NVIC Settings" tab. If that is done and you still aren't getting interrupts, how do you start the timer?  You either need to use a HAL_TIM function that ends in "_IT" or manually enable whichever interrupts you want in the timer registers.

     

     


    @AKozarzewski wrote:

    Hi

    I've configured automatically from IOC timer TIM16 as it is more basic timer and I need basic funcionality: do some action on timer interrupt, I use HAL driver, but handler is never called.

    initialisation is simple:

    void MX_TIM16_Init(void)
    {

    /* USER CODE BEGIN TIM16_Init 0 */

    /* USER CODE END TIM16_Init 0 */

    /* USER CODE BEGIN TIM16_Init 1 */

    /* USER CODE END TIM16_Init 1 */
    htim16.Instance = TIM16;
    htim16.Init.Prescaler = 511;
    htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim16.Init.Period = 50000;
    htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim16.Init.RepetitionCounter = 0;
    htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
    if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
    {
    Error_Handler();
    }
    /* USER CODE BEGIN TIM16_Init 2 */

    /* USER CODE END TIM16_Init 2 */

    }

    Timer is running , I can see it's changing value when read. It's set to reload periodicaly, it does that,  interrupt is enabled, given higher priority than others, just in case. Vector table is properly initialised. But interrupt handler never is called. What to check, any ideas?


    2 replies

    Bob S
    Bob SBest answer
    Super User
    June 19, 2023

    Did you enable the TIM16 interrupt in the NVIC.  In CubeMX, select TIM16 then click on the "NVIC Settings" tab. If that is done and you still aren't getting interrupts, how do you start the timer?  You either need to use a HAL_TIM function that ends in "_IT" or manually enable whichever interrupts you want in the timer registers.

     

     


    @AKozarzewski wrote:

    Hi

    I've configured automatically from IOC timer TIM16 as it is more basic timer and I need basic funcionality: do some action on timer interrupt, I use HAL driver, but handler is never called.

    initialisation is simple:

    void MX_TIM16_Init(void)
    {

    /* USER CODE BEGIN TIM16_Init 0 */

    /* USER CODE END TIM16_Init 0 */

    /* USER CODE BEGIN TIM16_Init 1 */

    /* USER CODE END TIM16_Init 1 */
    htim16.Instance = TIM16;
    htim16.Init.Prescaler = 511;
    htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim16.Init.Period = 50000;
    htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim16.Init.RepetitionCounter = 0;
    htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
    if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
    {
    Error_Handler();
    }
    /* USER CODE BEGIN TIM16_Init 2 */

    /* USER CODE END TIM16_Init 2 */

    }

    Timer is running , I can see it's changing value when read. It's set to reload periodicaly, it does that,  interrupt is enabled, given higher priority than others, just in case. Vector table is properly initialised. But interrupt handler never is called. What to check, any ideas?


    AKozarzewski
    Associate II
    June 19, 2023

    That all was fine. But you asked how I even ran what I have and it gave me thinking and I found what was wrong. I used HAL_TIM_Base_Start(&htim16); instead of HAL_TIM_Base_Start_IT(&htim16); , started to work immidiately.Thank you rubber duck ;)