2
\$\begingroup\$

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.

m.Alin
10.9k20 gold badges66 silver badges90 bronze badges
asked Oct 20, 2014 at 6:30
\$\endgroup\$
6
  • \$\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\$ Commented 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\$ Commented 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\$ Commented Oct 20, 2014 at 13:08
  • \$\begingroup\$ @KyranF -- clearly agree area51.stackexchange.com/proposals/70800/… \$\endgroup\$ Commented Oct 20, 2014 at 13:13
  • \$\begingroup\$ @ScottSeidman haha, wow. Okay then. I shall follow it, thanks for the link. \$\endgroup\$ Commented Oct 20, 2014 at 13:30

1 Answer 1

2
\$\begingroup\$

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.

Null
7,81618 gold badges38 silver badges49 bronze badges
answered Mar 20, 2015 at 22:59
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.