cancel
Showing results for 
Search instead for 
Did you mean: 

timer15 update interrupt

hendalage
Associate II
Posted on August 22, 2013 at 16:11

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!
3 REPLIES 3
Posted on August 22, 2013 at 17:04

RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, ENABLE);

Clock NOT Reset
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 22, 2013 at 17:06

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);
} 
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hendalage
Associate II
Posted on August 22, 2013 at 18:25

thank you very much! it worked.:)