sduino icon indicating copy to clipboard operation
sduino copied to clipboard

TIMER 2 interrupts not working

Open anupam-dubey opened this issue 2 years ago • 4 comments

Hi have used stm8s103 in sduino , i cannot able to write ISR for timer2 please help INTERRUPT_HANDLER(TIM2_UPD_OVF_IRQHandler, 13) /* TIM4 UPD/OVF */ {

i++; TIM2_ClearITPendingBit(TIM2_IT_UPDATE); TIM2_ClearFlag(TIM2_FLAG_UPDATE);

} void TIM2_Config(void) { //set at 100usec on overflow aims

/* TIM2 configuration:

  • TIM2CLK is set to 16 MHz, the TIM2 Prescaler is equal to 16 so the TIM2 counter clock used is 16 MHz / 16 = 1000 000 Hz
  • With 1000 000 Hz we can generate time base: max time base is 65536us if TIM2_PERIOD = 65535 --> (65535 + 1) * 1000000 = 65536 us min time base is 2 us if TIM2_PERIOD = 1 --> ( 1 + 1) * 1000000 = 2 us
  • In this example we need to generate a time base equal to 256 us so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */

/* Time base configuration / TIM2_TimeBaseInit(TIM2_PRESCALER_16, TIM2_PERIOD); / Clear TIM4 update flag / TIM2_ClearFlag(TIM2_FLAG_UPDATE); / Enable update interrupt */ TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);

/* enable interrupts */ // enableInterrupts();

/* Enable TIM4 */ TIM2_Cmd(ENABLE); }

anupam-dubey avatar Feb 22 '24 12:02 anupam-dubey

Having the same issue - and notice that the entry for the interrupt function does not seem to be made in the interrupt table:

                                     48 ;--------------------------------------------------------
                                     49 ; interrupt vector
                                     50 ;--------------------------------------------------------
                                     51         .area HOME
      000000                         52 __interrupt_vect:
      000000 82v00u00u00             53         int s_GSINIT ; reset
....
      000034 82 00 00 00             66         int 0x000000 ; int11
      000038 82v00u00u00             67         int _TIM1_CAP_COM_IRQHandler ; int12
      00003C 82 00 00 00             68         int 0x000000 ; int13
      000040 82 00 00 00             69         int 0x000000 ; int14
.....


For similar trivial code:

#include <stm8s.h>
volatile uint16_t now = 0;

INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
  TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
}

void setup() {
  TIM2_DeInit();
  TIM2_TimeBaseInit(TIM2_PRESCALER_1024, 60000);
  TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
  TIM2_Cmd(ENABLE);
}

void loop() {
};

dirkx avatar Feb 19 '25 17:02 dirkx

Confirmed that this indeed requires

INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13);      /* TIM2 UPD/OVF/BRK */
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14);          /* TIM2 CAP/COM */

to be uncommented in https://github.com/tenbaht/sduino/blob/0ce7e4c381028f6472eb29e8459210cee90b937d/sduino/stm8/cores/sduino/stm8s_it.h#L150 for this example code to work.

I guess what we need here is something like a '__weak' compiler trick. Or something fundamentally different when linking.

dirkx avatar Feb 19 '25 21:02 dirkx

**hello i had same problem

by changning interrupt vector 13 to 15 , it solved for me .

#pragma vector=15 // ok 
__interrupt void TIM2_UPDATE(void)    //4ms interrupt 
{    // toggle_led1;

my microntroller is stm8s105k6

best regards.**

sajadkkkkkk avatar Nov 13 '25 18:11 sajadkkkkkk

**hello i had same problem

by changning interrupt vector 13 to 15 , it solved for me .

#pragma vector=15 // ok 
__interrupt void TIM2_UPDATE(void)    //4ms interrupt 
{    // toggle_led1;

my microntroller is stm8s105k6

best regards.**

my ide is IAR

sajadkkkkkk avatar Nov 13 '25 18:11 sajadkkkkkk