历史上的今天
今天是:2024年09月08日(星期日)
2021年09月08日 | 【STM8S】 AWU低功耗模式
2021-09-08 来源:eefocus
/**
********************************** STM8S ***********************************
* @文件名 : bsp_awu.c
* @作者 : strongerHuang
* @库版本 : V2.2.0
* @文件版本 : V1.0.0
* @日期 : 2017年05月10日
* @摘要 : 自动唤醒源文件
******************************************************************************/
/*----------------------------------------------------------------------------
----------------------------------------------------------------------------*/
/* 包含的头文件 --------------------------------------------------------------*/
#include "AWU.h"
#include "stm8s_awu.h"
#include "stm8s_tim3.h"
/************************************************
函数名称 : AWU_LSIMeasurement
功 能 : LSI时钟测量
参 数 : 无
返 回 值 : 无
作 者 : 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);
}
/************************************************
函数名称 : AWU_Initializes
功 能 : AWU自动唤醒
参 数 : 无
返 回 值 : 无
作 者 : strongerHuang
*************************************************/
void AWU_Initializes(void)
{
AWU_LSICalibrationConfig(AWU_LSIMeasurement());//校正LSI时钟
AWU_Init(AWU_TIMEBASE_30S); //初始化AWU
enableInterrupts();
}
进入停机模式前可以关闭不需要的电源等,修改单片机IO口等。
halt(); //进入停机模式
中断发生后要清除标志位: AWU_GetFlagStatus();
可以与窗口看门狗一起用,但不能与独立看门狗一起用。
史海拾趣
|
评选优秀版主真是不简单啊,整理统计数据,还要计算,可真是忙坏了。不过想到各位版主们也是为坛子尽心尽力,评选这点工作又算得了什么呢?呵呵,好了,废话不多说,获奖版主们登场喽! 优秀版主:jxb01033016 总分 :   ...… 查看全部问答> |
|
把脉搏波中的呼吸信号去除 踝臂指数的测量对临床诊断有很重要的意义。目前测量的产品绝大多数都是基于幅度系数法测量收缩压,该方法缺乏扎实的理论基础,带有浓厚的经验性,测量值不够准确。通过实验分析以及柯氏音听诊法测量原理,发现检测脉搏重 ...… 查看全部问答> |
|
YL2440的板子,通过其EBOOT下载内核,可是总是校验和出错,如下所示: EthDown::TFTPD_OPEN::boot.bin -EbootSendBootmeAndWaitForTftp Download BIN file information: ----------------------------------------------------- [0]: Base Add ...… 查看全部问答> |
|
用如下的代码显示一个800 x 454 24bit的图片时,居然花了700ms时间(CPU主频600M)?请帮忙看看问题在哪里? case WM_PAINT: &n ...… 查看全部问答> |
|
一个应用程序 需要包含en.lib 这个lib是汇编和c编译的 举个头文件的例子:a.h #include \"mode.h\" #include \"frame.h\" #ifdef __cplusplus extern \"C\" { #endif int Str2mode(const char* str, enum Mode *mode); int M ...… 查看全部问答> |
|
3合1(STM32,STM8,STLINK)板中STM32原理图,样例程序,使用说明 补充一下STM32最小系统的原理图,样例程序和使用说明。 相关链接:https://bbs.eeworld.com.cn/upfiles/img/20095/2009511162619365.pdf… 查看全部问答> |




