0

I'm trying to implement this logic in STM8S103F3: 1) Controller wait for external interurpts on GPIOC (high by default) after initialization. 2.1) external interrupt triggered: if PIN5 of GPIOC is low, turn test led on, and start timer for 5s. 2.2) external interrupt triggered: if PIN5 of GPIOC is high, turn test led off and stop timer. 3) timer interrupt triggered: turn test led off.

My code:

#include "stm8s.h"
#include "stm8s_gpio.h"
#include "stm8s_exti.h"
#include "stm8s_tim1.h"

void tim1_update_handler() __interrupt(11)
{
    GPIO_WriteHigh(GPIOB, GPIO_PIN_5);
    TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
}

void portc_ext_int_handler() __interrupt(5)
{
    uint8_t state = GPIO_ReadInputData(GPIOC);
    if (state & GPIO_PIN_5) // PORTC pin 5 high, default state, button not pressed.
    {
        TIM1_SetCounter(0);
        TIM1_Cmd(ENABLE);
    }
    else // Button pressed.
    {
        GPIO_WriteLow(GPIOB, GPIO_PIN_5);
        TIM1_Cmd(DISABLE);
    }
}

int main(void)
{
    disableInterrupts();

    GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST);
    GPIO_Init(GPIOC, GPIO_PIN_ALL, GPIO_MODE_IN_PU_IT);

    EXTI_DeInit();
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_RISE_FALL);

    TIM1_TimeBaseInit(2000, TIM1_COUNTERMODE_UP, 5000, 0);
    TIM1_SelectOnePulseMode(TIM1_OPMODE_SINGLE);
    TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);

    enableInterrupts();

    while (1)
    {
        wfi();
    }
}

External interrupt is triggered fine, but timer interrupt does not triggers.

What i'm doing wrong with timer, and how i can gix it?

4

1 回答 1

0

这有点晚了,但可能是因为中断优先级,默认情况下设置为不中断已经在进行中的 ISR。更改 ITC_xxx 寄存器允许设置这些优先级,以便一个 IRQ 可以中断另一个 IRQ,这是您对定时器所需要的。

于 2019-12-15T14:40:11.573 回答