tenbaht / sduino

An Arduino-like programming API for the STM8
http://tenbaht.github.io/sduino/
GNU Lesser General Public License v2.1
347 stars 213 forks source link

ERROR: Timer and interrupt on STM8 using SPL #127

Open shrikant-lahase opened 3 years ago

shrikant-lahase commented 3 years ago

Hi @tenbaht ,

I am new to this environment. I am trying to do get IR signal and measure timings of IR signal. For that i want to use timer and external interrupt. I am writing code in Arduino IDE.

INTERRUPT_HANDLER (EXTI_PORTA_IRQHandler, 3){  
   GPIO_WriteReverse(GPIOB,GPIO_PIN_5);
}

void setup() {
  // put your setup code here, to run once:
   /* GPIO Configuration  -----------------------------------------*/
      GPIO_DeInit(GPIOA); //prepare Port A for working 
      GPIO_DeInit(GPIOB); // prepare Port B for working       

    GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_SLOW);   //Declare PB5 as push pull Output pin     
    GPIO_Init(GPIOA, GPIO_PIN_3,GPIO_MODE_IN_PU_IT); 

    /* Initialize the Interrupt sensitivity */
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOA, EXTI_SENSITIVITY_FALL_ONLY);
    EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY);

    enableInterrupts();

}

void loop() {
  // put your main code here, to run repeatedly:
 GPIO_WriteReverse(GPIOB,GPIO_PIN_5);

 delay(1000);

}```

I am getting error 
``` C:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/bin/sdcc sketch\stm8_interrupt.ino.cpp preproc\ctags_target_for_gcc_minus_e.cpp re12 -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ -E -MC -mstm8 -DSTM8S103 -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_STM8S_BLUE -DARDUINO_ARCH_STM8 -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\cores\sduino -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\variants\standard -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0/STM8S_StdPeriph_Driver/inc -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/include
Mark re12:C:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/bin/sdcc -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ -E -MC -mstm8 -DSTM8S103 -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_STM8S_BLUE -DARDUINO_ARCH_STM8 -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\cores\sduino -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\variants\standard -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0/STM8S_StdPeriph_Driver/inc -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/include sketch\stm8_interrupt.ino.cpp -o preproc\ctags_target_for_gcc_minus_e.cpp
cpp gefunden
C:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/bin/sdcc sketch\stm8_interrupt.ino.cpp sketch\stm8_interrupt.ino.cpp.o re2 -MMD -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ --less-pedantic -mstm8 -DSTM8S103 -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_STM8S_BLUE -DARDUINO_ARCH_STM8 -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\cores\sduino -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\variants\standard -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0/STM8S_StdPeriph_Driver/inc -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/include
Mark re2:C:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/bin/sdcc -MMD -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ --less-pedantic -mstm8 -DSTM8S103 -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_STM8S_BLUE -DARDUINO_ARCH_STM8 -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\cores\sduino -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0\variants\standard -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0/STM8S_StdPeriph_Driver/inc -IC:\Users\EmbedTech5\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/include sketch\stm8_interrupt.ino.cpp -o sketch\stm8_interrupt.ino.cpp.o
cpp gefunden
Multiple definition of _EXTI_PORTA_IRQHandler

exit status 1
Error compiling for board STM8S103F3 Breakout Board.

Please give any example code or starting point so that I can code for this on arduino IDE.

Thanks

stefaandesmet2003 commented 3 years ago

the compiler tells you the EXTI_PORTA_IRQHandler is already defined by the sduino library. Have a look at WInterrupts.c and you will understand how to integrate your ISR. The EXTI register can only be written with global interrupts disabled -> check your setup() You also need to enable the external interrupt at the port (GPIOx->CR2 register) Working example below. Hope this helps.

// test pin change interrupt on pin PC3
// the pin level on PC3 is copied onto the built-in led 

static void portc_irq (void) {
  digitalWrite(LED_BUILTIN,digitalRead(PC3));
}

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,LOW); //led on

  pinMode (PC3, INPUT_PULLUP);
  attachInterrupt(2,portc_irq, 0); // mode is not implemented in sduino, so we do the config manually after

  disableInterrupts(); // EXTI->CR1 only writable under disabled interrupts (CCR=3)
  EXTI->CR1 = 0x30; // set falling+rising interrupt for all pins on port C
  GPIOC->CR2 = 0x08; // enable ext interrupt on pin PC3
  enableInterrupts();
}

void loop() {
}
shrikant-lahase commented 3 years ago

the compiler tells you the EXTI_PORTA_IRQHandler is already defined by the sduino library. Have a look at WInterrupts.c and you will understand how to integrate your ISR. The EXTI register can only be written with global interrupts disabled -> check your setup() You also need to enable the external interrupt at the port (GPIOx->CR2 register) Working example below. Hope this helps.

// test pin change interrupt on pin PC3
// the pin level on PC3 is copied onto the built-in led 

static void portc_irq (void) {
  digitalWrite(LED_BUILTIN,digitalRead(PC3));
}

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,LOW); //led on

  pinMode (PC3, INPUT_PULLUP);
  attachInterrupt(2,portc_irq, 0); // mode is not implemented in sduino, so we do the config manually after

  disableInterrupts(); // EXTI->CR1 only writable under disabled interrupts (CCR=3)
  EXTI->CR1 = 0x30; // set falling+rising interrupt for all pins on port C
  GPIOC->CR2 = 0x08; // enable ext interrupt on pin PC3
  enableInterrupts();
}

void loop() {
}

Thank you very much. It worked.

shrikant-lahase commented 3 years ago

Thank you very much for a nice explanation. It worked.

Please give any similar example for a timer counter of stm8s103f3p

On Sun, Apr 11, 2021 at 10:13 PM stefaandesmet2003 @.***> wrote:

the compiler tells you the EXTI_PORTA_IRQHandler is already defined by the sduino library. Have a look at WInterrupts.c and you will understand how to integrate your ISR. The EXTI register can only be written with global interrupts disabled -> check your setup() You also need to enable the external interrupt at the port (GPIOx->CR2 register) Working example below. Hope this helps.

// test pin change interrupt on pin PC3 // the pin level on PC3 is copied onto the built-in led

static void portc_irq (void) { digitalWrite(LED_BUILTIN,digitalRead(PC3)); }

void setup() { pinMode(LED_BUILTIN,OUTPUT); digitalWrite(LED_BUILTIN,LOW); //led on

pinMode (PC3, INPUT_PULLUP); attachInterrupt(2,portc_irq, 0); // mode is not implemented in sduino, so we do the config manually after

disableInterrupts(); // EXTI->CR1 only writable under disabled interrupts (CCR=3) EXTI->CR1 = 0x30; // set falling+rising interrupt for all pins on port C GPIOC->CR2 = 0x08; // enable ext interrupt on pin PC3 enableInterrupts(); }

void loop() { }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tenbaht/sduino/issues/127#issuecomment-817336319, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR3MTSUQJTMS5NHUDR647BLTIHGTTANCNFSM42UGTLXA .

stefaandesmet2003 commented 3 years ago

TIM4 is in use for millis() / micros() Have a look at wiring-millis.c

shrikant-lahase commented 3 years ago

Thanks, I'll check it out. Where is this file wiring-millis.c available ?

On Mon, Apr 12, 2021 at 1:50 PM stefaandesmet2003 @.***> wrote:

TIM4 is in use for millis() / micros() Have a look at wiring-millis.c

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tenbaht/sduino/issues/127#issuecomment-817597596, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR3MTSQ7MWY3LEROW6ECLL3TIKUMVANCNFSM42UGTLXA .

stefaandesmet2003 commented 3 years ago

you must be mistaking this issue page for stackoverflow ;)

neoblack2 commented 3 years ago

the compiler tells you the EXTI_PORTA_IRQHandler is already defined by the sduino library. Have a look at WInterrupts.c and you will understand how to integrate your ISR. The EXTI register can only be written with global interrupts disabled -> check your setup() You also need to enable the external interrupt at the port (GPIOx->CR2 register) Working example below. Hope this helps.

// test pin change interrupt on pin PC3
// the pin level on PC3 is copied onto the built-in led 

static void portc_irq (void) {
  digitalWrite(LED_BUILTIN,digitalRead(PC3));
}

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,LOW); //led on

  pinMode (PC3, INPUT_PULLUP);
  attachInterrupt(2,portc_irq, 0); // mode is not implemented in sduino, so we do the config manually after

  disableInterrupts(); // EXTI->CR1 only writable under disabled interrupts (CCR=3)
  EXTI->CR1 = 0x30; // set falling+rising interrupt for all pins on port C
  GPIOC->CR2 = 0x08; // enable ext interrupt on pin PC3
  enableInterrupts();
}

void loop() {
}

Dont work on STM8S105K6.

neoblack2 commented 3 years ago

Is it so hard for the author to make working code with interrupts? Moreover, there is an example, but not working.

stefaandesmet2003 commented 3 years ago

for me the code works on STM8S103. I don't have a STM8S105, but from the datasheet the register map looks identical for what concerns this example. "dont work" isn't very precise, if you need useful help :)