STM8S AWU low power mode

Publisher:rockstar7Latest update time:2019-11-07 Source: eefocusKeywords:STM8S  AWU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


/**

  ********************************** STM8S *************** ********************

  * @file name: bsp_awu.c

  * @Author: strongerHuang

  * @Library version: V2.2.0

  * @File version: V1.0.0

  * @Date: May 10, 2017

  * @Summary: Automatic wakeup source file

  ******************************************************************************/

/*----------------------------------------------------------------------------

  ----------------------------------------------------------------------------*/

/* Included header files--------------------------------------------------------------*/

#include "AWU.h"

 

#include "stm8s_awu.h"

#include "stm8s_tim3.h"

/************************************************

Function name: AWU_LSIMeasurement

Function: LSI clock measurement

Parameters: None

Return value: None

Author: strongerHuang

*************************************************/

uint32_t AWU_LSIMeasurement(void)

{

  uint32_t lsi_freq_hz = 0x0;

  uint32_t fmaster = 0x0;

  uint16_t ICValue1 = 0x0;

  uint16_t ICValue2 = 0x0;

 

  /* Get master frequency */

  fmaster = CLK_GetClockFreq();

 

  /* Enable the LSI measurement: LSI clock connected to timer Input Capture 1 */

  AWU->CSR |= AWU_CSR_MSR;

 

#if defined (STM8S903) || defined (STM8S103) || defined (STM8S003)

  /* Measure the LSI frequency with TIMER Input Capture 1 */

 

  /* Capture only every 8 events!!! */

  /* Enable capture of TI1 */

TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, TIM1_ICPSC_DIV8, 0);

 

  /* Enable TIM1 */

  TIM1_Cmd(ENABLE);

 

  /* wait a capture on cc1 */

  while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1);

  /* Get CCR1 value*/

  ICValue1 = TIM1_GetCapture1();

  TIM1_ClearFlag(TIM1_FLAG_CC1);

 

  /* wait a capture on cc1 */

  while((TIM1->SR1 & TIM1_FLAG_CC1) != TIM1_FLAG_CC1);

  /* Get CCR1 value*/

  ICValue2 = TIM1_GetCapture1();

  TIM1_ClearFlag(TIM1_FLAG_CC1);

 

  /* Disable IC1 input capture */

  TIM1->CCER1 &= (uint8_t)(~TIM1_CCER1_CC1E);

  /* Disable timer2 */

  TIM1_Cmd(DISABLE);

 

#else  

  /* Measure the LSI frequency with TIMER Input Capture 1 */

 

  /* Capture only every 8 events!!! */

  /* Enable capture of TI1 */

  TIM3_ICInit(TIM3_CHANNEL_1, TIM3_ICPOLARITY_RISING, TIM3_ICSELECTION_DIRECTTI, TIM3_ICPSC_DIV8, 0);

 

  /* Enable TIM3 */

  TIM3_Cmd(ENABLE);

 

/* wait a capture on cc1 */

  while ((TIM3->SR1 & TIM3_FLAG_CC1) != TIM3_FLAG_CC1);

/* Get CCR1 value*/

  ICValue1 = TIM3_GetCapture1();

  TIM3_ClearFlag(TIM3_FLAG_CC1);

 

  /* wait a capture on cc1 */

  while ((TIM3->SR1 & TIM3_FLAG_CC1) != TIM3_FLAG_CC1);

    /* Get CCR1 value*/

  ICValue2 = TIM3_GetCapture1();

TIM3_ClearFlag(TIM3_FLAG_CC1);

 

  /* Disable IC1 input capture */

  TIM3->CCER1 &= (uint8_t)(~TIM3_CCER1_CC1E);

  /* Disable timer3 */

  TIM3_Cmd(DISABLE);

#endif /* STM8S903 || STM8S103*/

 

  /* Compute LSI clock frequency */

  lsi_freq_hz = (8 * fmaster) / (ICValue2 - ICValue1);

  

  /* Disable the LSI measurement: LSI clock disconnected from timer Input Capture 1 */

  AWU->CSR &= (uint8_t)(~AWU_CSR_MSR);

 

 return (lsi_freq_hz);

}

 

/************************************************

Function name: AWU_Initializes

Function: AWU automatic wake-up

Parameters: None

Return value: None

Author: strongerHuang

*************************************************/

void AWU_Initializes(void)

{

  AWU_LSICalibrationConfig(AWU_LSIMeasurement()); //Calibrate LSI clock

  AWU_Init(AWU_TIMEBASE_30S); //Initialize AWU

  enableInterrupts();

}

 

 

Before entering the shutdown mode, you can turn off unnecessary power supplies, modify the microcontroller IO ports, etc.


halt(); //Enter shutdown mode


After the interrupt occurs, clear the flag: AWU_GetFlagStatus();


Can be used with a window watchdog, but not with an independent watchdog.

Keywords:STM8S  AWU Reference address:STM8S AWU low power mode

Previous article:STM8S FLASH and EEPROM read and write operations
Next article:STM8S103K3 I2C

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号