I've just started using STM8 microcontrollers, specifically the STM8S003F3P6 chip, in my own custom test board. The board works and I am able to blink an LED on PA3 without using an interrupt. However, when I try to make the blink take place in the Tim2_OVF interrupt, nothing happens. I think the interrupt is not taking place. What have I missed?? I have declared the function, "rim" has been added, checked the lst file that shows the int vector has been written. I am adding the hex file also for your reference:
My complete code is below. It blinks the led 5 times before the timer TIM2 is started. My SDCC version is 3.9.0 Your help is appreciated.
#include <stdint.h>
#include <stm8s.h>
#define F_CPU 2000000UL
#define LED_PIN 3
void delay_ms(uint16_t ms);
void mS125_isr() __interrupt(TIM2_OVF_ISR);
char tix, i,j,six, mins, b_chgLED;
void mS125_isr() __interrupt(TIM2_OVF_ISR)
{
tix++;
if(tix==8)
{
six++;
tix=0;
}
if(six==60)
{
mins++;
six=0;
}
if(tix==0 || tix==4)
{
PA_ODR ^= (1 << LED_PIN);
}
TIM2_SR1 &= ~(1 << TIM2_SR1_UIF);
}
//-------------------------------------------------------------------------
//Main routine starts
void main()
{
PA_DDR |= (1 << LED_PIN); // configure PA3 as output
PA_CR1 |= (1 << LED_PIN); // push-pull mode
/* Prescaler = 128 */
TIM2_PSCR = 0b00000111;
/* Frequency = F_CLK / (2 * prescaler * (1 + ARR))
* = 2 MHz / (2 * 128 * (1 + 1952)) = 8 Hz */
TIM2_ARRH = 0x07;
TIM2_ARRL = 0xa1;
for(i=0;i<10;i++)
{
/* toggle pin initially with a delay */
PA_ODR ^= (1 << LED_PIN);
delay_ms(125);
}
__asm__("rim\n");
TIM2_IER |= (1 << TIM2_IER_UIE); // Enable Update Interrupt
TIM2_CR1 |= (1 << TIM2_CR1_CEN); // Enable TIM2
while (1){};
}
//---------------------------------------------------------------------------
void delay_ms(uint16_t ms)
{
long li;
for (li = 0; li < ((F_CPU / 18000UL) * ms); li++)
__asm__("nop\n");
}