cancel
Showing results for 
Search instead for 
Did you mean: 

TIM1 ISR not triggering - STM32f4xx

dibs
Associate II
Posted on September 17, 2013 at 00:15

I am trying to use the ISR for TIM1, but it does not want to trigger. I run the following code in debug mode on my IDE, but the TIM1 ISR code never gets executed.

I believe that the problem may have something to do with an extra enable needed for the advanced control timers, but have yet been unable to find it.

Also, I would appreciate any tips on how to make the following code more readable for you.

/* Includes ------------------------------------------------------------------*/

&sharpinclude ''stm32f4xx.h''

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private Variables */

uint16_t uhPrescalerValue = 0;

NVIC_InitTypeDef NVIC_InitStructure;

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

/* Functions */

int main(void)

{

uhPrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 10000000) - 1;

/* TIM clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

/* Enable the TIM4 interrupt */

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  

NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;

NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;

  NVIC_Init(&NVIC_InitStructure);

/* Time Base configuration */

  TIM_TimeBaseStructure.TIM_Prescaler = uhPrescalerValue;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

//Enable TIM1 output

TIM_CtrlPWMOutputs(TIM1,ENABLE);

/* TIM counter enable */

  TIM_Cmd(TIM1, ENABLE);

TIM_Cmd(TIM4, ENABLE);

//TIM IT Config

TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);

while (1){

}

}

void TIM4_IRQHandler(void) {

TIM_ClearITPendingBit(TIM4, TIM_IT_Update);

}

void TIM1_CC_IRQHandler(void) {

TIM_ClearITPendingBit(TIM3, TIM_IT_Update);

}

void TIM1_CC_IRQHandler(void);

void TIM4_IRQHandler(void);

#stm32f4 #stm32f4 #interrupts #tim1 #isr #vector-table
7 REPLIES 7
Posted on September 17, 2013 at 00:42

TIM1 uses multiple interrupts for different sources

For Update

TIM1_UP_TIM10_IRQHandler

You'll want to change the NVIC (TIM1_UP_TIM10_IRQn), and have the service routine clear TIM1, not TIM3
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dibs
Associate II
Posted on September 17, 2013 at 02:04

Thanks again clive. That works. 

In order to use the CC interrupt, would you need to set up one of the IC or OC functions on one of the TIM1 channels?

Posted on September 17, 2013 at 02:35

Yes, and the other interrupts in NVIC as required. You could however modify the vector table in startup_stm32f4xx.s to all use the same service routine.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dibs
Associate II
Posted on October 31, 2013 at 03:28

Ahh good idea. I am finding now that I need to use this technique for other purposes.

dibs
Associate II
Posted on January 17, 2014 at 22:41

In order to make two different interrupts use the same ISR is it correct to say:

startup_stm32f4xx.s

EXTI9_5_IRQHandler\

        PROC

        EXPORT EXTI9_5_IRQHandler              [WEAK]

        IMPORT EXTI_COM_IRQ_Handler

        B      EXTI_COM_IRQ_Handler

        ENDP

EXTI15_10_IRQHandler\

        PROC

        EXPORT EXTI15_10_IRQHandler              [WEAK]

        IMPORT EXTI_COM_IRQ_Handler

        B      EXTI_COM_IRQ_Handler

        ENDP

;EXTI9_5_IRQHandler

;EXTI15_10_IRQHandler

---

in file.cpp

    NVIC_InitTypeDef NVIC_InitStructure;

    

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority             = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd                      = ENABLE;

    NVIC_InitStructure.NVIC_IRQChannel                              = EXTI9_5_IRQn;

    NVIC_Init(&NVIC_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel                              = EXTI15_10_IRQn;

    NVIC_Init(&NVIC_InitStructure);

    void EXTI_COM_IRQ_Handler__irq(void) {    }

in file.h:

extern ''C'' {

void EXTI_COM_IRQ_Handler__irq(void) ;

}

Posted on January 17, 2014 at 23:05

I'd probably just change them in the vector table and save the unnecessary branch

..

                DCD     EXTI9_5_IRQHandler                ; External Line[9:5]s

..

                DCD     EXTI15_10_IRQHandler              ; External Line[15:10]s

..

too

IMPORT EXTI_COM_IRQ_Handler

..

  DCD EXTI_COM_IRQHandler

..

  DCD EXTI_COM_IRQHandler

..

 NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;

    NVIC_Init(&NVIC_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;

    NVIC_Init(&NVIC_InitStructure);

void EXTI_COM_IRQHandler(void) // cdecl?!

{

}

in file.h:

extern ''C'' {

void EXTI_COM_IRQHandler(void) ;

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dibs
Associate II
Posted on January 17, 2014 at 23:18

Is it true to say that the interrupts vector list in stm32f4xx.h is the mapping for the list in the External Interrupts section of startup_stm32f4xx.s? This would mean that as long as you did not mess with the order, it does not really matter what you call each item is the assembly list?