• 大小: 3KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-11-29
  • 语言: 其他
  • 标签: 低功耗  STM32  rtc  

资源简介

使用RTC唤醒低功耗三种模式,实测功耗为1UA左右,sleep模式下功耗为1MA左右。

资源截图

代码片段和文件信息

/*
*********************************************************
** Filename: stop_mode.c
** Abstract: 使用STM32L151C8T6MCU,使用RTC唤醒STOP和STANDBY模式下的低功耗低功耗时长可以人为的进行设置
** 设置低功耗时长时请参考头文件中关于时长的宏定义
** 使用注意事项:使用CubeMX生成函数时,在main()函数后会自动生成SystemClock_Config()函数,此程序中调用了该函数。
** 如果该函数在其他文件中,请将该.h文件加入,以免发生错误;
** Date : 2018-01-04 
** Author:王翔武
*********************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include “pwr_mode_rtc.h“
#include “main.h“

RTC_HandleTypeDef RTCHandle; //RTC结构体变量

//进入STOP模式低功耗,使用RTC功能唤醒,其中stoptime单位为S,如设置1,低功耗1秒后唤醒
void enter_stop_rtc(float stoptime)
{
uint32_t i; //局部变量,用于计算低功耗时长
system_power_config();

    /* Disable Wakeup Counter */
    HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);

/*To configure the wake up timer to 4s the WakeUpCounter is set to 0x242B:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 
Wakeup Time base = 16 /(~37KHz) = ~0432 ms
Wakeup Time = ~5s = 0432ms  * WakeUpCounter
==> WakeUpCounter = ~5s/0432ms = 11562 */
i = stoptime*2396;
    HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle i RTC_WAKEUPCLOCK_RTCCLK_DIV16);
    
    /* Enter Stop Mode */
    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON PWR_STOPENTRY_WFI);
SystemClock_Config();
}

//进入STANDBY模式低功耗,使用RTC功能唤醒,其中standbytime单位为S,如设置1,低功耗1秒后唤醒
void enter_standby_rtc(float standbytime)
{
uint32_t i; //局部变量,用于计算低功耗时长
system_power_config();

if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); 
}
  
    /* Disable Wakeup Counter */
    HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);

/*To configure the wake up timer to 4s the WakeUpCounter is set to 0x242B:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 
Wakeup Time base = 16 /(~37KHz) = ~0432 ms
Wakeup Time = ~5s = 0432ms  * WakeUpCounter
==> WakeUpCounter = ~5s/0432ms = 11562 */
i = standbytime*2396;
    HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle i RTC_WAKEUPCLOCK_RTCCLK_DIV16);
    
/* Clear all related wakeup flags */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

 /* Enter the Standby mode */
HAL_PWR_EnterSTANDBYMode();
}

//进入SLEEP模式低功耗,使用RTC功能唤醒,其中sleeptime单位为S,如设置1,低功耗1秒后唤醒
void enter_sleep_rtc(float sleeptime)
{
uint32_t i; //局部变量,用于计算低功耗时长


system_power_config();

    /* Disable Wakeup Counter */
    HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);

/*To configure the wake up timer to 4s the WakeUpCounter is set to 0x242B:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 
Wakeup Time base = 16 /(~37KHz) = ~0432 ms
Wakeup Time = ~5s = 0432ms  * WakeUpCounter
==> WakeUpCounter = ~5s/0432ms = 11562 */
i = sleeptime*2396;
    HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle i RTC_WAKEUPCLOCK_RTCCLK_DIV16);
    
    /*Suspend Tick increment to prevent wakeup by Systick interrupt. 
    Otherwise the Systick interrupt will wake up the device within 1ms (HAL time bas

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5920  2018-01-04 18:18  PWR_RTC低功耗模式代码\pwr_mode_rtc.c

     文件        428  2018-01-04 18:14  PWR_RTC低功耗模式代码\pwr_mode_rtc.h

     文件        337  2018-01-04 19:13  PWR_RTC低功耗模式代码\低功耗介绍.txt

     目录          0  2018-01-04 18:22  PWR_RTC低功耗模式代码

----------- ---------  ---------- -----  ----

                 6685                    4


评论

共有 条评论