AnsweredAssumed Answered

Cann't enter capture interrupt subroutine

Question asked by Lei Sun on Aug 8, 2017

hi all, I have recently tried the official code according to the application note AN2822: STM8S and STM8A high speed internal oscillator calibration. Since I use STM8S003k3 MC, I modified the code from timer 3 to timer 1 channel 1. But I found that I could not enter the timer1 capture interrupt subroutine (the capture interrupt subroutine is never called), although I have checked the necessary registers' values using debug mode and all registers are correctly set.

I have tried as mentioned in AN2822 the signal generater input with 50Hz frequency on the PC1 port (TIM1_CH1) but it seems that the rising edge of the input signal is never captured by STM8S003k3.

 

I have also edited a simple example for the overflow interrupt and capture interrupt of timer1:

 

The main function:

 

#include "stm8s_lib.h"
#include "stdlib.h"

u16 cntr;
u16 LEDflag;

main()
{
GPIO_DeInit(GPIOC);
GPIO_Init(GPIOC, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(GPIOC, GPIO_PIN_6, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(GPIOC, GPIO_PIN_7, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_WriteHigh(GPIOC, GPIO_PIN_5);
GPIO_WriteHigh(GPIOC, GPIO_PIN_6);
GPIO_WriteHigh(GPIOC, GPIO_PIN_7);


GPIO_Init(GPIOC, GPIO_PIN_1, GPIO_MODE_IN_FL_NO_IT);

cntr = 0;
LEDflag = 0;
CLK_DeInit();

CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); // Clock divider to HSI/1
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1); // Fcpu division factor: /1


TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV8, 0x03);

TIM1_UpdateRequestConfig(TIM1_UPDATESOURCE_REGULAR); // Update interupt request is sent only when the counter overflow
TIM1_UpdateDisableConfig(DISABLE); // Update Event Enable

TIM1_ClearITPendingBit(0xFF); // Clear all pending interupts

TIM1_ITConfig(TIM1_IT_CC1, ENABLE); // Capture/Compare 1 Interrupt Enable
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE); // Update Interrupt Enable
TIM1_Cmd(ENABLE); // enable counter

while(1){};

}

 

 

stm8s_it.c:

 

extern u16 cntr;
extern u16 LEDflag;

@near @interrupt void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)
{
   TIM1_ClearITPendingBit(TIM1_IT_UPDATE); // clear all interupt flags

   return;

}

@near @interrupt @svlreg void TIM1_CAP_COM_IRQHandler (void)
{
   GPIO_WriteLow(GPIOC, GPIO_PIN_5);
   if ( TIM1_GetFlagStatus(TIM1_FLAG_CC1) == SET ) {
      GPIO_WriteLow(GPIOC, GPIO_PIN_5);
      cntr++;
      if (cntr > 10) {
         cntr = 0;
         if (LEDflag == 0) { //toggle LED C6
            LEDflag = 1;
            GPIO_WriteLow(GPIOC, GPIO_PIN_6);
         }
      else {
         LEDflag = 0;
         GPIO_WriteHigh(GPIOC, GPIO_PIN_6);
      }
   }
}
else {
   GPIO_WriteLow(GPIOC, GPIO_PIN_7);

}
TIM1_ClearITPendingBit(TIM1_IT_CC1);
return;

}

 

The interrupt vector stm8_interrupt_vector.c

 

...

(void @near (*)())0x8200,
TIM1_UPD_OVF_TRG_BRK_IRQHandler,/* irq11 - TIM1 Update/Overflow/Trigger/Break interrupt */

(void @near (*)())0x8200,
TIM1_CAP_COM_IRQHandler, /* irq12 - TIM1 Capture/Compare interrupt */

...

 

I  used the standard firmware. I could not get any timer1 channel1 capture interrupt and the capture interrupt subroutine is never entered.

I want to ask if anybody has similar experience on this problem: why the timer1_channel1 rising signal cannot be

captured and the interrupt subroutine cannot be called? I would appreciate if you give me just some hints. Thanks all!

 

Bo

Outcomes