AnsweredAssumed Answered

HAL Timer interrupt

Question asked by marmsoler.martin on Jul 30, 2015
Latest reply on Aug 2, 2015 by marmsoler.martin
Hello,

I tried to use the Timer interrupt. In the examples of the STM Discovery they used the HAL_TIM_PeriodElapsedCallback handle function. But with this does'nt work (The don't used HAL_NVIC_EnableIRQ(TIM2_IRQn), why?). Then I enabled the IRQ with HAL_NVIC_EnableIRQ(TIM2_IRQn). Now it calls everytime the Default Handler even if I implented the TIM2_IRQHandler function.
What is the error I make?

01.//TIM2: APB1
02.// Timer channel 2 as base timer
03.void timer2Init()
04.{
05.    /* Variables */
06.    TIM_HandleTypeDef initTimBase;
07. 
08.    /* enable Clocks */
09.    __HAL_RCC_TIM2_CLK_ENABLE();
10. 
11.    // every 1ms an overflow
12.    initTimBase.Instance = TIM2;
13.    initTimBase.Init.CounterMode = TIM_COUNTERMODE_UP;
14.    initTimBase.Init.Period = 32;
15.    initTimBase.Init.Prescaler = 1344;
16.    initTimBase.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
17.    initTimBase.Init.RepetitionCounter = 0;
18. 
19. 
20.    //HAL_TIM_Base_Start(&initTimBase);
21. 
22.    //__HAL_TIM_CLEAR_IT(&initTimBase, TIM_IT_UPDATE);
23. 
24. 
25. 
26.    HAL_TIM_Base_Init(&initTimBase);
27.    HAL_TIM_Base_Start_IT(&initTimBase);
28. 
29.    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
30.    HAL_NVIC_EnableIRQ(TIM2_IRQn);
31. 
32.}
33. 
34. 
35.void TIM2_IRQHandler(void)
36.{
37.    int i = 0;
38.    i++;
39. 
40.    //HAL_TIM_IRQHandler(&initTimBase);
41.}

Outcomes