cancel
Showing results for 
Search instead for 
Did you mean: 

TIM16 never calls interrupt handler in STM32WLE4

AKozarzewski
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Bob S
Principal

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?


View solution in original post

2 REPLIES 2
Bob S
Principal

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?


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 😉