Topic : TIM2 interrupt problem

Forum : ST7/STM8

Original Post
Post Information Post
December 23, 2010 - 8:22pm
Guest

Hi,
I'm trying to create a blinking led using TIM2 and interrupt on STM8S207RB.
The interrupt routine simply toggle the led state but I never reach the code because the timer doesn't run.
After checking all example code , I have no idea for solve the problem.
Using simulator the counter of tim2 is always lock on 0x0000 and reading it with TIM2_GetCounter give me the same 0x0000 result.
please give me some indications or suggestion.
Thanks in advance.

#include "stm8s.h"
#include "stm8s_conf.h"
#include "stm8s_gpio.c"
#include "stm8s_clk.c"
#include "stm8s_it.h"
#include "stm8s_tim2.c"

#define LEDS_PORT (GPIOD)
#define LED1_PIN (GPIO_PIN_5) //alive led
#define LED2_PIN (GPIO_PIN_6) //blinking led (in theory...)

void TIM2_UPD_OVF_BRK_IRQHandler(void) interrupt 13
{
GPIO_WriteReverse(LEDS_PORT, (LED2_PIN));
}

void Delay(u16 nCount)
{
while (nCount != 0)
nCount--;
}

void main(void)
{
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
CLK_FastHaltWakeUpCmd (ENABLE);

GPIO_Init(LEDS_PORT,LED1_PIN , GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(LEDS_PORT,LED2_PIN , GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(SW_IN,IN1_PIN , GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(SW_IN,IN2_PIN , GPIO_MODE_IN_FL_NO_IT);

TIM2_DeInit();
TIM2_ARRPreloadConfig (DISABLE);
TIM2_SelectOnePulseMode (TIM2_OPMODE_REPETITIVE);
TIM2_UpdateDisableConfig (ENABLE);
TIM2_UpdateRequestConfig (TIM2_UPDATESOURCE_GLOBAL );
TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
TIM2_TimeBaseInit(TIM2_PRESCALER_32,0xfefe);
enableInterrupts();
TIM2_Cmd(ENABLE) ;

// following lines blink an "alive " led
while (1)
{
/* LED TOGGLE */
GPIO_WriteReverse(LEDS_PORT, (LED1_PIN));
Delay((u16)60000);
Delay((u16)60000);
}
}

Replies
Post Information Post
+1
0
-1
December 24, 2010 - 9:43am
Raisonance Support Team

Hi Paolo,

The easiest way to handle this is to check the "Testall" example in the Ride7 installation directory, in Examples\STM8\REva\STM8S208\Testall. This example contains plenty of useful information, and has a 1ms timer interrupt, so you can check the code.

Best Regards,