/**
********************************** 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.
Previous article:STM8S FLASH and EEPROM read and write operations
Next article:STM8S103K3 I2C
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- EEWORLD University Hall----Introduction to Computer Vision
- 【NXP Rapid IoT Review】 Comprehensive Review and Engineering Resource Summary
- Has anyone used STM8L151K4T6? Is the DAC of this chip stable?
- The official website CC2541SDK cannot print via serial port
- Decoupling capacitors
- Summary of pspice circuit simulation
- Playing with Zynq Serial 40——[ex59] Binocular vision image acquisition and display example based on Zynq
- Summary and analysis of interference problems in circuit design
- Does the dummy pad have any impact on the electrical characteristics of the PCB?
- [HC32F460 Development Board Review] NO.2 Familiarity with the development process and different peripheral functions