2022-02-14 08:38 PM
#include "stm8l15x.h"
#include "stm8l15x_gpio.h"
#include "stm8l15x_itc.h"
#include "stm8l15x_exti.h"
#include "stm8l15x_clk.h"
#include "stm8l15x_rtc.h"
#include "stm8l15x_tim2.h"
#include "stm8l15x_tim1.h"
#include "stm8l15x_tim3.h"
#include "stm8l15x_tim4.h"
#include "stm8l15x_adc.h"
#include "stm8l15x_pwr.h"
// void Halt_init();
// void GPIO_LowPower_Config(void);
//
void Delay(__IO uint32_t nCount)
{ /* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
void main()
{
// Halt_Init();
TIM1_Cmd(DISABLE);
TIM2_CtrlPWMOutputs(DISABLE);
TIM2_Cmd(DISABLE);
TIM3_Cmd(DISABLE);
TIM4_Cmd(DISABLE);
ADC_Cmd(ADC1, DISABLE);
PWR_PVDCmd(DISABLE);
/* Switch to LSI as system clock source */
/* system clock prescaler: 1*/
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI);
CLK_SYSCLKSourceSwitchCmd(ENABLE);
while (CLK_GetFlagStatus(CLK_FLAG_LSIRDY) == 0);
CLK_HSICmd(DISABLE);
CLK_HSEConfig(CLK_HSE_OFF);
/* Set STM8 in low power */
PWR_UltraLowPowerCmd(ENABLE);
/* Set GPIO in low power*/
/* Configure unused pins as output push-pull 0 to enter low power */
/* Port A */
GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);
/* Port B not AIN */
GPIO_Init(GPIOB, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Slow);
/* Port B LEDs, so they don't flash at power on */
GPIO_Init(GPIOB, GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5, GPIO_Mode_Out_PP_High_Slow);
/* Port C not wakeup pin!! */
GPIO_Init(GPIOC, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6, GPIO_Mode_Out_PP_Low_Slow);
/* Port D */
GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);
/* Port E */
GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);
/* Port F */
GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);
/* Stop RTC Source clock */
CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1);
/* Stop clock RTC and LCD */
CLK_PeripheralClockConfig(CLK_Peripheral_RTC, DISABLE);
CLK_PeripheralClockConfig(CLK_Peripheral_LCD, DISABLE);
GPIO_Init(GPIOC, GPIO_Pin_3, GPIO_Mode_Out_PP_Low_Fast);
GPIO_ToggleBits(GPIOC, GPIO_Pin_3);
Delay(90000);
EXTI_ClearITPendingBit(EXTI_IT_Pin7);
halt();
GPIO_Init(GPIOE, GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Fast);
GPIO_ToggleBits(GPIOE, GPIO_Pin_7);
Delay(90000);
}
Solved! Go to Solution.
2022-02-22 12:39 AM
Hello. This line is clearing one of the bits within EXTI_SR1 register which indicates occurrence of external interrupt on any of pin7 within MCU. In STM8L devices you can configure EXTI interrupts per pin or by port (in this second case EXTI_SR2 register is taken into consideration).
2022-02-22 12:39 AM
Hello. This line is clearing one of the bits within EXTI_SR1 register which indicates occurrence of external interrupt on any of pin7 within MCU. In STM8L devices you can configure EXTI interrupts per pin or by port (in this second case EXTI_SR2 register is taken into consideration).
2022-02-22 09:16 PM
Thank you!!