AnsweredAssumed Answered

TIM2 is not generating any interrupts on STM32f051

Question asked by Evert on Dec 4, 2012
Latest reply on Jan 30, 2014 by kamba.hugues
Dear all,

I've an issue with TIM2 on the STM32f051
I did a port from STM32f103, however the interrupt is not activated anymore.
A big difference is that I use a f0discovery board, so I make use of an internal RC occilator.
I did some changes to use the HSI for clocking the PLL at the correct frequency
Since TIM14 is working, it looks like initialising the clock is working fine.
This is how the clock is initialized:

static void Clk_Init(void)
{
RCC_HSICmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

/* Init PLL (8MHZ/2)*12 = 48MHZ */
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_12);
RCC_PLLCmd(ENABLE);

while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

FLASH_PrefetchBufferCmd(ENABLE);
FLASH_SetLatency(FLASH_Latency_1);
/* TIM2,3,14 at 48MHz */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2 |
RCC_APB1Periph_TIM3 |
RCC_APB1Periph_TIM14 | RCC_APB1Periph_USART2, ENABLE);
}

This is how the initalisation of the timer is done

void init_timer(void)
{
/* Peripherals InitStructure define */
static TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
static NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseStructure.TIM_Period = 48;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* set up Timer 2 */

NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); /* Prescaler configuration */

TIM_PrescalerConfig(TIM2, (NR_MSEC_FOR_MAIN * MSEC), TIM_PSCReloadMode_Immediate);
TIM_InternalClockConfig(TIM2);
TIM_Cmd(TIM2, ENABLE); /* switch timer on */
}

After this initialisation, the micro never enters the TIM2_IRQHandler()
Does someone has any idea? did I forgot any initalisation?
TIM14 is working fine, however it does not make use of an IRQHandler().

Regards,

Evert Huijben

Outcomes