2011-10-19 02:53 AM
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 @ 72MHzHere 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 regardsAMK2011-10-19 04:24 AM
''crashes'' is unacceptable problem description from a coder.
You forgot to include the interrupt handler.2011-10-19 04:36 AM
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.