cancel
Showing results for 
Search instead for 
Did you mean: 

Active/Halt wakeup with RTC

serkanakblt
Associate
Posted on May 03, 2013 at 14:36

Hi ,

I am a new user of STM8.  In my project I am using Active/halt mode an it wakes up with RTC Wakeup operation. My problem is, it is always waking up same times. it's equal to 3ms. I want update auto wake up times. 

I am trying to change RTC_SetWakeUpCounter(30000) but it is not setting wake up times. How can ı change wake up times.

Thank you for your comments.

Here is the example code;

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

#include ''stm8l15x.h''

#include ''stm8l151f3.h''

#define ENABLE 1

#define DISABLE 0

void RTC_Config(void)

{

RTC_WriteProtectionCmd(DISABLE);

  CLK_RTCClockConfig(CLK_RTCCLKSource_LSI, CLK_RTCCLKDiv_1);

while (CLK_GetFlagStatus(CLK_FLAG_LSIRDY) == RESET);

  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);

  RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div2);

  RTC_ITConfig(RTC_IT_WUT, ENABLE);

  enableInterrupts();

}

void GPIO_LowPower_Config(void)

{

GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);

   GPIO_Init(GPIOB, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Slow);

   GPIO_Init(GPIOB, GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5, GPIO_Mode_Out_PP_High_Slow);

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

   GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);

   GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);

   GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);

}

void Halt_Init(void)

{

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

RTC_WriteProtectionCmd(DISABLE);

RTC_Config();

RTC_WriteProtectionCmd(DISABLE);

CFG_GCR&=0xFD;

RTC_SetWakeUpCounter(30000);

  RTC_WakeUpCmd(ENABLE);

   CLK_PeripheralClockConfig(CLK_Peripheral_LCD, DISABLE);

}

void main(void)

{

Halt_Init();

halt();

while(1)

{

//GPIO_ToggleBits(GPIOB,GPIO_Pin_0);

}

}

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

2 REPLIES 2
serkanakblt
Associate
Posted on May 03, 2013 at 16:56

  while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);

  /* wait for 1 second for the LSE Stabilisation */

I dont wait 1 sencond is it too important to wait it?
wenbingma2012
Associate II
Posted on June 19, 2013 at 04:59

1. your system clock and rtc clock is LSI. I think you don't need to wait LSE clock stable. 

2. In your code, RTC wakeup step is 2/38KHz = 0.0526ms. you can change wake up counter to set wakeup time.

I uses LSE clock source as RTC clock. it works well.