cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2_IRQHandler(void) not working on STM32F407Vg

Bogdan
Senior
Posted on June 03, 2014 at 20:17

Hi guys, i encounter some problems using timer interrupts.

I tryied several code examples from the web, but the problem stil occurs... I am using IAR 6.3 as ide, i cant figure out what is wrong in the interrupt routine, why does not blinks that led3. The setup is on a discovery f4 board If i try to declare the void TIM2_IRQHandler as extern ''c'' void TIM2_IRQHandler(void) the complier returns me some error mesages Error[Pe040]: expected an identifier Error[Pe260]: explicit type is missing (''int'' assumed)

#include <
stm32f4xx.h
>
#include <
stm32f4xx_i2c.h
>
#include <
stm32f4xx_i2c.c
>
#include ''stm32f4xx_gpio.c''
#include ''stm32f4xx_rcc.c''
#include ''system_stm32f4xx.c''
#include ''my_i2c.c''
#include ''stm32_ub_lcd_2xc''
#define I2Cx I2C1
#include ''delay.c''
#include ''delay.h''
#include ''misc.c''
#include ''i2c_com.c'' // MPU comunication functions
//#include ''MPU6c'' // MPU functions library
#include ''stm32f4xx_tim.h''
#include ''stm32f4xx_tim.c''
#include ''stm32f4_discovery.h''
#include ''stm32f4_discovery.c''
#include ''stm32f4xx_it.h''
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
/* LED3 toggling */
STM_EVAL_LEDToggle(LED3);
}
}
int main(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Enable the TIM2 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Initialize LED3 mounted on STM32F0-Discovery */
STM_EVAL_LEDInit(LED3);
/* Turn on LED3 */
STM_EVAL_LEDOn(LED3);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 42000 - 1; // To KHz
TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // To Hz
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM Interrupts enable */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
/* Infinite loop */
while (1);
}

4 REPLIES 4
Posted on June 03, 2014 at 20:54

Given the odd construction of your project, I'm going to hazard that you don't have startup_stm32f4xx.s in it, and you are not using the example templates for IAR in the firmware library.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Bogdan
Senior
Posted on June 04, 2014 at 06:42

Hi clive, thanks for the tip.

However i think i`m a bit lost here, how exactly can i import that file?

I`ved copied the file in the libs directory, but after i complied the code stil nothing with the interrupt request.

Is there a special statement wich i must declare in main.c ?

Bogdan
Senior
Posted on June 04, 2014 at 13:03

Hi, i am back with good news,  i created a subfolder in my project folder. In wich i put ''system_stm32f4xx.c'', system_stm32f4xx.h and startup_stm32f4xx.s

The first two files i had them before, except the .s file, i copied to the libs folder and the problem stil remains.

After i added that file to the project workspace it all worked well.

Now my led is blinking at 1HZ

Ch33rs 🙂

Posted on June 04, 2014 at 13:05

Do you have no experience using IDE (IAR, VS, etc)? You don't #include source files, you are supposed to add them to the project view of your source tree. I don't use IAR, but surely there is a File Add, or Add File to Group type operation? You add startup_stm32f4xx.s to the tree.

You shouldn't need to #include all the individual library .H files either, if you follow the model of the examples in the firmware library, you'd just need #include ''stm32f4xx.h'' and have a local copy of stm32f4xx_conf.h and set the INCLUDE PATHS and DEFINES for the project within the OPTIONS for the project.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..