cancel
Showing results for 
Search instead for 
Did you mean: 

I am using the STM8L1526 discovery board. I want to go into HALT mode and then come out using GPIO Pin as an external interrupt.

ASing.20
Associate II
 
1 REPLY 1
ASing.20
Associate II

I tried to use this code, but I am not unable to do it.

I don't know which pin acts as an interrupt and either it is active high or active low.

This code was originally not written by me. I have copied it from STM community.

///////////////////////////////////////////

///////////////////////////////////////////

Here's what I'm doing for the STM8L151 and it drops current to 0.5uA. This is full halt, but if you want to keep RTC active, just comment out those lines. One thing, you have to clear the wakeup INT before halt. Here, I'm using EXTI pin7 for wakeup.

Halt_Init();

EXTI_ClearITPendingBit(EXTI_IT_Pin7);

halt();

void Halt_Init(void)

{

  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*/   

  GPIO_LowPower_Config();

  /* 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);

}

void GPIO_LowPower_Config(void)

{

  /* 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);

}