Question
stm32f4-discovery strange problem with timer interrupt HELP Please!
Posted on February 26, 2014 at 18:49
Hello!
I am stm32f4 beginner. Learning timer interrupt (IAR 6.3). Task is this: once per second by a timer interruptincrease some value and LED (GPIO_Pin_12) to light, as a works fine signal. Problem so far. The code below compiles (only compiles) and downloads in tostm32f4-discovery board fine. But (big hairy but), when debugger quitTIM2_Configuration()stm32f4 board starts to flashing red and green LED (led near mini-usb port) and nothing happend (as if the timer does not want to work with the interruption). ControlGPIO_Pin_12 led does not ignite. I tried to do it with other timers with different variations of code, but it always turned the timer as it does not want to work with the interruption. I look at other sites and write code that should works well with interruptions. But everythingthe same. What is wrong?void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIOA/D clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = ((SystemCoreClock / 1000000) / 2) - 1; // 1 MHz timebase
TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // 1 KHz update
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable TIM2 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
extern ''C''
{
void TIM2_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
nBuf++;
GPIO_SetBits(GPIOD, GPIO_Pin_12);
}
}
int main()
{
GPIO_InitTypeDef GPIO_InitStructurePortD;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructurePortD.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructurePortD.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructurePortD.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_UP;//
GPIO_Init(GPIOD, &GPIO_InitStructurePortD);
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
TIM2_Configuration();
while(1)
{
}
}