AnsweredAssumed Answered

Trouble with timer interrupt on STM32F103C8T6 -> default handler

Question asked by nicht.will on Oct 16, 2016
Latest reply on Oct 18, 2016 by waclawek.jan
Hello,

I have trouble to get Timer2 interrupt on a STM32F103C8T6 minimal board running. The Timer2 is working fine, but when I enable the interrupt for this timer my program ends up in the default handler (infinite loop). It seems that the interrupt is generated but the program does not find the right address for the interrupt service routine.

Thank you for your help.

01.#include "stm32f10x_conf.h"
02. 
03.void InitializeLEDs()
04.{
05.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
06.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
07. 
08.    GPIO_InitTypeDef gpioStructure;
09.    gpioStructure.GPIO_Pin = GPIO_Pin_12;
10.    gpioStructure.GPIO_Mode = GPIO_Mode_Out_PP;
11.    gpioStructure.GPIO_Speed = GPIO_Speed_50MHz;
12.    GPIO_Init(GPIOB, &gpioStructure);
13. 
14.    gpioStructure.GPIO_Pin = GPIO_Pin_13;
15.    GPIO_Init(GPIOC, &gpioStructure);
16. 
17.    GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
18.    GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET);
19.}
20. 
21.void InitializeTimer()
22.{
23.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
24. 
25.    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
26. 
27.    TIM_TimeBaseInitTypeDef timerInitStructure;
28.    timerInitStructure.TIM_Prescaler = 40000;
29.    timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
30.    timerInitStructure.TIM_Period = 500;
31.    timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
32.    timerInitStructure.TIM_RepetitionCounter = 0;
33.    TIM_TimeBaseInit(TIM2, &timerInitStructure);
34.    TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
35.    TIM_Cmd(TIM2, ENABLE);
36.}
37. 
38. 
39.void EnableTimerInterrupt()
40.{
41.    NVIC_InitTypeDef nvicStructure;
42.    nvicStructure.NVIC_IRQChannel = TIM2_IRQn;
43.    nvicStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
44.    nvicStructure.NVIC_IRQChannelSubPriority = 0x00;
45.    nvicStructure.NVIC_IRQChannelCmd = ENABLE;
46.    NVIC_Init(&nvicStructure);
47.}
48. 
49.void TIM2_IRQHandler()
50.{
51.    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
52.    {
53.        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
54.        if(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_13)){
55.          GPIO_WriteBit(GPIOC, GPIO_Pin_13, RESET);
56.        }else{
57.          GPIO_WriteBit(GPIOC, GPIO_Pin_13, SET);
58.        }
59.    }
60.}
61. 
62.int main()
63.{
64. 
65.    SystemInit();
66. 
67.    //TIM_ClearITPendingBit(TIM2, 0xff);
68. 
69.    InitializeLEDs();
70.    InitializeTimer();
71.    EnableTimerInterrupt();
72. 
73.    for (;;)
74.    {
75.        for (int i = 0; i < 1000000; i++)
76.            asm("nop");
77.        if(GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12)){
78.          GPIO_WriteBit(GPIOB, GPIO_Pin_12, RESET);
79.        }else{
80.          GPIO_WriteBit(GPIOB, GPIO_Pin_12, SET);
81.        }
82.    }
83.}

Attachments

Outcomes