AnsweredAssumed Answered

TIM3 interrupt crashes then being initialized

Question asked by Malke on Oct 19, 2011
Latest reply on Oct 19, 2011 by Clive One
Hi,

Can any please help me out here. I'm trying to set up a timer-interrupt, TIM3, for every second. But when I'm trying to initialize the TIM3 interrupt my system crashes :(

I'm running @ 72MHz

Here is my code for initializing the TIM3 interrupt:

void initTIM3Irq(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
    GPIO_InitTypeDef GPIO_InitStructure;


    /* Enable clock for TIM3 - otherwise we can't configure it */
    RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3, ENABLE);

    TIM_DeInit (TIM3);            // Deinitialize TIM3 to its default reset values.

    // Basic timer initialization
    TIM_TimeBaseStructInit (&TIM_TimeBaseInitStruct);
    
    TIM_TimeBaseInitStruct.TIM_Period = 9999;     .
    TIM_TimeBaseInitStruct.TIM_Prescaler = 7199;  // Prescaler value: Set to 1MHz = 1us clocking
    TIM_TimeBaseInitStruct.TIM_ClockDivision = 0;
    TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Down;
    
    TIM_TimeBaseInit (TIM3, &TIM_TimeBaseInitStruct);


    /* TIM3 enable counter */
    TIM_Cmd( TIM3, ENABLE );
    
    /* Enable TIM3 Update interrupt */
    TIM_ITConfig (TIM3, TIM_IT_Update, ENABLE);


    /* Enable the TIM3 global interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // changed from 0
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; // changed from 15
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init (&NVIC_InitStructure);  


    /* Disable TIM3 clocks - to save power */
    RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3, DISABLE);         
}

Best regards
AMK

Outcomes