cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot enter low power mode STM8L052C6

Billy Bob
Associate II
Posted on April 18, 2018 at 06:00

Hi,

I feel like I've been through the reference manual a million times, but I cant figure out how to get my project into low power mode.

I'm driving a LCD screen with a counter on it. I have two external switches to wake up count up and down. And I'm using timer4 to hopefully wake up periodically and do some work. 

I need two low power modes, one with the LCD on and it just wakes up to handle a button press or a timer4 timeout.

The other low power mode will turn off the LCD and will only wake up on a button press. It needs to wake up and not reset because I don't want to lose count on the LCD.

To save power I'm running off LSI clock.  

Code below. Any ideas would be greatly appreciated. I'm new to STM8

main()

{

  CLK_CKDIVR = 0b0; //Div clock by 1

  CLK_SWR = 0x02; //Sys clock is LSI (38kHz)

  CLK_SWCR |= 0x2; //Tell system to switch clocks to one defined in SWR

  while(CLK_SWCR & 1);

  CLK_ICKCR &= 0b11111110; //HSI Off

  CFG_GCR |= 0b10; //main context not restored after WFI/HALT

  lcd_init(); //Do this first or its really slow.

  PB_DDR = 0; //Set pins as Inputs. By default

  //INPUTS PULLED UP

  PA_CR1 = 0x8C;

  PB_CR1 = 0xFF;

  PC_CR1 = 0xF7;

  PD_CR1 = 0x3C;

  PE_CR1 = 0xB6;

  PE_CR1 = 0x01;

  PB_CR2 = 0b110; //PB1 and PB2 interrupt enable

  EXTI_CR1 = 0b101000; //Port1 and 2 to falling edge only interrupt

  CLK_PCKENR1 |= 0x04; //Enable CLK to Timer4

  TIM4_CR1 = 0b101; //Enable Timer4

  TIM4_IER = 1; //Timer4 interrupt enable

  TIM4_PSCR = 1; //CLK/2(8) so CLK div 16

  while(CLK_SWCR & 1);

  {_asm('rim\n');} //enable interrupts

  while (1){

    if (readyToSleep == 1){

      readyToSleep = 0;

      CLK_PCKENR1 = 0; //Disable clocks to perfs

      CLK_PCKENR2 = 0;

      CLK_PCKENR3 = 0;

      EXTI_SR1 = 0; //Clear interrupts

      EXTI_SR2 = 0;

      TIM4_SR1 = 0;

      {_asm('HALT\n');}

    }

    else{

      {_asm('WFE\n');}

      {_asm('JRA next\n');}

      {_asm('next:\n');}

      //{_asm('WFI\n');}

    }

  }

}

#halt #sleep #wfe #stm8l052c6 #wfi #lcd #low-power #stm8
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 22, 2018 at 15:57

Hello,

Please find attached a simple example project. It was developed using STVD IDE (Cosmic compiler) and Standard Peripheral Library for STM8L.

I tested this applicaion on STM8L Discovery kit. It contains STM8L152C6 device, but I am sure you can run it also on your STM8L052C6. With this code STM8L will enter Halt mode and it will wake up from EXTI interrupt (PC1). After waking up MCU will togle PE7. PC1 is connected to push button and PE7 is connected to LED. This application allowed me to reach 0.4uA in Halt mode, please see the picture below.

0690X00000604agQAA.jpg

My main.c file looks like below:

#include ''stm8l15x.h''  main() { GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);  GPIO_Init(GPIOE, GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOC, GPIO_Pin_1, GPIO_Mode_In_FL_IT);  EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling);  enableInterrupts();  PWR_UltraLowPowerCmd(ENABLE); PWR_FastWakeUpCmd(ENABLE);  while (1) { halt(); GPIO_ToggleBits(GPIOE, GPIO_Pin_7); } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Regards

Szymon

________________

Attachments :

stm8l_test.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxfJ&d=%2Fa%2F0X0000000b0l%2FJYjZV78PopqHEklYyaP24E.oP.OYcTkwGEeg5hxI1pc&asPdf=false

View solution in original post

4 REPLIES 4
Billy Bob
Associate II
Posted on April 21, 2018 at 23:11

Okay, I really need help. I just started a new project with nothing in it. Everything is default. All I am doing is calling halt. 

#include 'STM8L052C6.h'

void main(void)

{

     {_asm('HALT\n');}

     while (1);

}

When running normal I'm drawing 1.3mA. When I call HALT, I can get around 200uA. No where near the advertised 0.4uA. What am I doing wrong? At this point I'm thinking errata, but I don't see anything noted anywhere. Please help. Anyone have example code?

Posted on April 22, 2018 at 15:57

Hello,

Please find attached a simple example project. It was developed using STVD IDE (Cosmic compiler) and Standard Peripheral Library for STM8L.

I tested this applicaion on STM8L Discovery kit. It contains STM8L152C6 device, but I am sure you can run it also on your STM8L052C6. With this code STM8L will enter Halt mode and it will wake up from EXTI interrupt (PC1). After waking up MCU will togle PE7. PC1 is connected to push button and PE7 is connected to LED. This application allowed me to reach 0.4uA in Halt mode, please see the picture below.

0690X00000604agQAA.jpg

My main.c file looks like below:

#include ''stm8l15x.h''  main() { GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);  GPIO_Init(GPIOE, GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Fast); GPIO_Init(GPIOC, GPIO_Pin_1, GPIO_Mode_In_FL_IT);  EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling);  enableInterrupts();  PWR_UltraLowPowerCmd(ENABLE); PWR_FastWakeUpCmd(ENABLE);  while (1) { halt(); GPIO_ToggleBits(GPIOE, GPIO_Pin_7); } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Regards

Szymon

________________

Attachments :

stm8l_test.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxfJ&d=%2Fa%2F0X0000000b0l%2FJYjZV78PopqHEklYyaP24E.oP.OYcTkwGEeg5hxI1pc&asPdf=false
Posted on May 09, 2018 at 07:36

Thanks. I was able to get it to work with that example code. I've noticed I can still only get it to work if I compile for 'Debug' because if I compile for 'Release' and load that onto the unit, it never goes into low power. But this is good enough for now. Thanks.