2013-08-22 07:11 AM
hi,
i'm using an f3 disco board and i want to configure its timer 15 with an update interrupt. i want it to be interrupted every one second to toggle two on-board LEDs. following is the code for timer15 and NVIC configuration.void
Init_TIM15()
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
int
Prescaler_Val = (SystemCoreClock/2000)-1;
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_LEDOff(LED3);
STM_EVAL_LEDOn(LED4);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, ENABLE);
/* Enable the TIM15 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_TIM15_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure);
TIM_TimeBaseInitStructure.TIM_Period = 2000;
TIM_TimeBaseInitStructure.TIM_Prescaler = 0;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM15, &TIM_TimeBaseInitStructure);
TIM_PrescalerConfig(TIM15, Prescaler_Val, TIM_PSCReloadMode_Immediate);
TIM_ITConfig(TIM15, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM15, ENABLE);
}
int
main(
void
)
{
int
count = 0;
Init_TIM15();
while
(1){
count = TIM_GetCounter(TIM15);
}
}
and here is the code i placed insidestm32f30x_it.c file.
void
TIM1_BRK_TIM15_IRQHandler(
void
)
{
if
(TIM_GetITStatus(TIM15, TIM_IT_Update) != RESET){
TIM_ClearITPendingBit(TIM15, TIM_IT_Update);
STM_EVAL_LEDToggle(LED3);
STM_EVAL_LEDToggle(LED4);
}
}
when i run it, the LEDs stays in initial states and never toggles. in the main function, i updated a variable (count) continuously with the timer's count value and watched it under debug mode and it says that the value of the count is not in scope.
can someone please tell me if i'm making any mistakes with above codes??
thanks in advance!
2013-08-22 08:04 AM
RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, ENABLE);
Clock NOT Reset
2013-08-22 08:06 AM
void Init_TIM15()
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
int Prescaler_Val = (SystemCoreClock/2000)-1;
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_LEDOff(LED3);
STM_EVAL_LEDOn(LED4);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);
/* Enable the TIM15 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_TIM15_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseInitStructure.TIM_Prescaler = Prescaler_Val;
TIM_TimeBaseInitStructure.TIM_Period = 2000 - 1;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM15, &TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM15, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM15, ENABLE);
}
int main(void)
{
int count = 0;
Init_TIM15();
while(1){
count = TIM_GetCounter(TIM15);
}
}
2013-08-22 09:25 AM
thank you very much! it worked.:)