I have coded for Timer 4 in a STM32f407vg discovery board. But while debugging the control is not entering the ISR. Please find the code below and help:
void InitializeTimer()
{
TIM_TimeBaseInitTypeDef timerInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
timerInitStructure.TIM_Prescaler = 0;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 255;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
/*Initialise timer 4 */
TIM_TimeBaseInit(TIM4, &timerInitStructure);
TIM_Cmd(TIM4, ENABLE);
}
void EnableTimerInterrupt()
{
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = TIM4_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
nvicStructure.NVIC_IRQChannelSubPriority = 1;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
}
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
}
With this configuration I am not able to enter an ISR.
-
\$\begingroup\$ This is firmware/software, and not about electronics design. It's about the use of a development board. I don't see how it's allowed as on-topic.. Anyway have you asked this on the STM forums? \$\endgroup\$KyranF– KyranF2014年10月20日 08:46:21 +00:00Commented Oct 20, 2014 at 8:46
-
\$\begingroup\$ @KyranF Embedded programming at this level has long been held to be on topic here. Chances are that the expertise here is better than in other programming stacks for such questions, and perhaps communicated in a slightly different way for embedded specialties. \$\endgroup\$Scott Seidman– Scott Seidman2014年10月20日 12:58:35 +00:00Commented Oct 20, 2014 at 12:58
-
1\$\begingroup\$ @ScottSeidman I really feel that we need an embedded programming (microprocessor and single-board computer style size) stack exchange, to bridge the gap between Stack Overflow and EE.SE \$\endgroup\$KyranF– KyranF2014年10月20日 13:08:03 +00:00Commented Oct 20, 2014 at 13:08
-
\$\begingroup\$ @KyranF -- clearly agree area51.stackexchange.com/proposals/70800/… \$\endgroup\$Scott Seidman– Scott Seidman2014年10月20日 13:13:22 +00:00Commented Oct 20, 2014 at 13:13
-
\$\begingroup\$ @ScottSeidman haha, wow. Okay then. I shall follow it, thanks for the link. \$\endgroup\$KyranF– KyranF2014年10月20日 13:30:16 +00:00Commented Oct 20, 2014 at 13:30
1 Answer 1
You not only have to configure the timer mode, interval etc. and enable it but you also have to tell the timer on what events should the interrupt be generated. You can do this with a function:
void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
This is obviously because the timer may generate an interrupt signal for many different reasons, not just when it for example overflows.