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?