cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding STM32F207 Timers ISR

er
Associate II
Posted on November 26, 2014 at 11:11

Hi, 

I am very new to 32 bit micro-controllers.I am using STM32f207VG controller.I want to use Timer2 to generate Interrupt every 1 ms.

Timer clock is set to 36MHz. I have written the following code for timer ISR.

My code is going into timer ISR and glowing the LED.But it think it is not coming back from Timer ISR.Because when the value of Trace couter is >1000 it should turn off the LED.But it is never happening.Please Find the code Below and let me know where i m doing wrong.

Thanks in advance :) !!

void Timer2Init();

int main(void)

{

  

  /* Clear WatchDog Registers */

  WatchDog_clear();

  /*configure Clock ; SystemCoreClock = 120000000 */

  SysTick_Config(SystemCoreClock / 1000);

  /*Initialise Watchdog Timer*/

  Watchdog_Init();

  /*Initialise the CPU clock*/

  CPU_initializeClocks();

  /*Initialise GPIO's ,UART's , LED's */

  CPU_initializeGPIO();

  CPU_initializeInterrupts();

  Timer2Init(); 

  TIM_Cmd(TIM2,ENABLE);

  while (1) 

  { 

    

  WatchDog_Reload(); //FeedinG Watcdog 

  if(traceCnt > 1000)

  {

    LedRed(OFF);

    TIM_Cmd(TIM2,DISABLE);

  }

  

  }//end while (1)  

} //end main()

void Timer2Init()

{

   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

   NVIC_InitTypeDef   NVIC_InitStructure;

   TIM_DeInit(TIM2);

   

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

   

  TIM_TimeBaseStructure.TIM_Period = 0x8CA0;

  TIM_TimeBaseStructure.TIM_Prescaler = 2;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode =  TIM_CounterMode_Up;

  

  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

 

  /* Enable TIM2 Interrupt channel */

  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);

  

  TIM_ITConfig(TIM2, TIM_IT_Update,ENABLE);

 

  

}

/*******************************************************************************

 * Function Name  : TIM2_IRQHandler

 * Description    : This function handles TIM2 global interrupt request.

 * Input          : None

 * Output         : None

 * Return         : None

 *******************************************************************************/

void TIM2_IRQHandler(void)

{

  if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)

  {    

      traceCnt++;

      LedRed(ON);

    /* Clear CC4 Interrupt pending bit */

    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

  }

}

#regardinr-timer-isr
4 REPLIES 4
Posted on November 26, 2014 at 17:54

Using C++ (.cpp)?

Whole swaths of code missing, so in the debugger where does the code end up? Can you breakpoint the IRQ?

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

Hi Clive1,

Thanks alot for the response.

I am using embedded c (IAR workbench).

Yes ,i tried this code in debug mode also.I put a break point at traceCnt++ (in TIM2_IRQHandler()).Code stops at break point.This shows that interrupt is occuring.Also LEDRed(ON)  function works.As LED is glowing.

I also put a break point in main loop.But code did not stop here.

I am unable to understand why code is not able to go back to main loop once ISR is called.

Thanks in advance :)  !

Posted on November 27, 2014 at 08:18

Is traceCnt declared volatile?

JW

er
Associate II
Posted on November 27, 2014 at 10:30

Hi,

Thanks for the response.It really helped.

I was missing the same. Keyword ''Volatile''.

It is working fine now.

Thanks a lot :) !!