Re: [Sdcc-user] STM8 interrupt example ?

2017-01-23 Thread Травкин Роман
Typical interrupt is "void HandlerName() __interrupt(n)", where n -- interrupt number according to chip datasheet. Handler name could be anything you want. For trap interrupt use "void HandlerName() _trap". void TIM4_OVF_handler() __interrupt(23){      TIM4->SR1 &= ~TIM4_SR1_UIF;   // Reset flag as RM0016 states     ms_cnt++;} void TIM1_OVF_UPD_TRG_handler() __interrupt(11){        TIM1->SR1 &= ~TIM1_SR1_UIF; // Reset flag as RM0016 states  tim1_ovf_num++;} void TIM2_OVF_UPD_handler() __interrupt(13){        TIM2->SR1 &= ~TIM2_SR1_UIF; // Reset flag as RM0016 states  tim2_ovf_num++;} 22.01.2017, 14:56, "aarrgghh.co.uk" :Are there any concise SDCC examples of interrupt handling for the STM8?I'm particularly interested in the STM8003F3 however anything for thatfamily of processors will help.There are excellent general examples on colecovision that have all thecode in a single file which makes understanding what is going on veryclear.http://www.colecovision.eu/stm8/These have helped me get going but none of them cover an interrupt and Iam struggling to get a basic timer 1 interrupt call working or evencompiling as I don't know if the error is in incorrect use of registersor general SDCC syntax or my C coding.I don't really want to flood the place with derpy Questions if I canavoid it.RegardsRuss--Check out the vibrant tech community on one of the world's mostengaging tech sites, SlashDot.org! http://sdm.link/slashdot___Sdcc-user mailing listSdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] STM8 interrupt example ?

2017-01-23 Thread aarrgghh.co.uk

Thanks I've tried that but I'm still not having any luck.
This is my code.

#include 

#define CLK_DIVR(*(volatile uint8_t *)0x50C6)

#define TIM1_CR1(*(volatile uint8_t *)0x5250)
#define TIM1_IER(*(volatile uint8_t *)0x5254)
#define TIM1_SR1(*(volatile uint8_t *)0x5255)
#define TIM1_CNTRH(*(volatile uint8_t *)0x525E)
#define TIM1_CNTRL(*(volatile uint8_t *)0x525F)
#define TIM1_PSCRH(*(volatile uint8_t *)0x5260)
#define TIM1_PSCRL(*(volatile uint8_t *)0x5261)

#define PD_ODR(*(volatile uint8_t *)0x500f)
#define PD_DDR(*(volatile uint8_t *)0x5011)
#define PD_CR1(*(volatile uint8_t *)0x5012)

void main(void)
{
CLK_DIVR = 0x00; // Set the frequency to 16 MHz

TIM1_PSCRH = 0x00; // Configure timer
TIM1_PSCRL = 0x80;

TIM1_CR1 = 0x01; //Enable timer
TIM1_IER = 0x01; //Enable interrupt - update event

PD_DDR = 1<<3;
PD_CR1 = 1<<3;


while(1){
}
}

void TIM1_overflow_Handler() __interrupt(11)
{
TIM1_SR1 &= ~1; //reset interrupt
PD_ODR ^= 1 << 3; //toggle LED
}


On 23/01/17 10:37, Травкин Роман wrote:
Typical interrupt is "void HandlerName() __interrupt(n)", where n -- 
interrupt number according to chip datasheet. Handler name could be 
anything you want. For trap interrupt use "void HandlerName() _trap".

void TIM4_OVF_handler() __interrupt(23)
{
  TIM4->SR1 &= ~TIM4_SR1_UIF;   // Reset flag as RM0016 states
ms_cnt++;
}
void TIM1_OVF_UPD_TRG_handler() __interrupt(11)
{
TIM1->SR1 &= ~TIM1_SR1_UIF; // Reset flag as RM0016 states
  tim1_ovf_num++;
}
void TIM2_OVF_UPD_handler() __interrupt(13)
{
TIM2->SR1 &= ~TIM2_SR1_UIF; // Reset flag as RM0016 states
  tim2_ovf_num++;
}
22.01.2017, 14:56, "aarrgghh.co.uk" :


Are there any concise SDCC examples of interrupt handling for the STM8?
I'm particularly interested in the STM8003F3 however anything for that
family of processors will help.

There are excellent general examples on colecovision that have all the
code in a single file which makes understanding what is going on very
clear.
http://www.colecovision.eu/stm8/

These have helped me get going but none of them cover an interrupt and I
am struggling to get a basic timer 1 interrupt call working or even
compiling as I don't know if the error is in incorrect use of registers
or general SDCC syntax or my C coding.
I don't really want to flood the place with derpy Questions if I can
avoid it.

Regards
Russ

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net 
https://lists.sourceforge.net/lists/listinfo/sdcc-user




--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot


___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] STM8 interrupt example ?

2017-01-23 Thread Травкин Роман
You haven't enabled interrupts. Assembler command "rim" -- enables interrrupts, "sim" --disasbles.add __asm__ ("rim") before while(1). PD_DDR = 1<<3; PD_CR1 = 1<<3;   __asm__ ("rim");    while(1){    } You may also may look at adapted stm8s.h from SPL https://yadi.sk/d/Asn1BiuX3AbQsB 24.01.2017, 00:23, "aarrgghh.co.uk" :Thanks I've tried that but I'm still not having any luck.This is my code.#include #define CLK_DIVR    (*(volatile uint8_t *)0x50C6)#define TIM1_CR1    (*(volatile uint8_t *)0x5250)#define TIM1_IER    (*(volatile uint8_t *)0x5254)#define TIM1_SR1    (*(volatile uint8_t *)0x5255)#define TIM1_CNTRH    (*(volatile uint8_t *)0x525E)#define TIM1_CNTRL    (*(volatile uint8_t *)0x525F)#define TIM1_PSCRH    (*(volatile uint8_t *)0x5260)#define TIM1_PSCRL    (*(volatile uint8_t *)0x5261)#define PD_ODR    (*(volatile uint8_t *)0x500f)#define PD_DDR    (*(volatile uint8_t *)0x5011)#define PD_CR1    (*(volatile uint8_t *)0x5012)void main(void){    CLK_DIVR = 0x00; // Set the frequency to 16 MHz    TIM1_PSCRH = 0x00; // Configure timer    TIM1_PSCRL = 0x80;   TIM1_CR1 = 0x01; //Enable timer    TIM1_IER = 0x01; //Enable interrupt - update event    PD_DDR = 1<<3;    PD_CR1 = 1<<3;   while(1){    }}void TIM1_overflow_Handler() __interrupt(11){    TIM1_SR1 &= ~1; //reset interrupt    PD_ODR ^= 1 << 3; //toggle LED} --
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user