Skip to main content
malikkleist
Visitor II
October 19, 2011
Question

TIM3 interrupt crashes then being initialized

  • October 19, 2011
  • 2 replies
  • 718 views
Posted on October 19, 2011 at 11:53

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

    This topic has been closed for replies.

    2 replies

    domen23
    Associate II
    October 19, 2011
    Posted on October 19, 2011 at 13:24

    ''crashes'' is unacceptable problem description from a coder.

    You forgot to include the interrupt handler.
    Tesla DeLorean
    Guru
    October 19, 2011
    Posted on October 19, 2011 at 13:36

    Need to enable the NVIC before enabling interrupts.

    Need to leave the TIM3 clock enabled, otherwise it STOPS.

    Prescaler gets you to 10 KHz, not 1 MHz, update interrupt once per second.

    No interrupt handler provided.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..