查看: 2782|回复: 0

STM32F103之RTC唤醒唤醒低功耗模式

[复制链接]
  • TA的每日心情
    难过
    2021-2-27 22:16
  • 签到天数: 1568 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    发表于 2019-1-27 12:25:25 | 显示全部楼层 |阅读模式
    分享到:
    这段时间在公司最一个低功耗的项目,采用的的STM32F103的最低功耗standby模式,进入最低功耗模式后,电流降到了3uA,和芯片手册上的大致相同。对进入低功耗模式,网上有很多程序,我在这里把我的粘贴上来,仅供参考,io口的具体配置要通过电路原理图来设置。

    void enter_standby_mode(void)
    {        
    //IO口配置
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//_IPD输入上拉
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//_IPD输入下拉
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//_IPD输入上拉
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin=(GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//_IPD输入下拉
    GPIO_Init(GPIOA, &GPIO_InitStructure);//配置A口 其中9 10 为串口,13 14为TMS TCK,共16口
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//_IPD输入上拉
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉
    GPIO_Init(GPIOB, &GPIO_InitStructure);//配置B口 共16口
    GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉
       GPIO_Init(GPIOC, &GPIO_InitStructure);//端口C的配置,共16个端口
    GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_2);
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉
       GPIO_Init(GPIOD, &GPIO_InitStructure);//端口D的配置,1个端口
    //一共64端口。ABCD配置了49个端口,VBAT VDD VSS等11个电源端口不用配置 49+11=60
    //没有配置的端口有复位端口NRST、boot0端口、PD0(OSC_IN)、PD1(OSC_OUT)等4个端口         
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);        //使能PWR外设时钟
       PWR_EnterSTANDBYMode();         //进入待命(STANDBY)模式

    }

    在成功设置低功耗模式后,需要周期性的运行程序,然后进入低功耗,间隔意见时间后,继续运行程序。这时就需要用到RTC时钟来进行对低功耗模式的唤醒。低功耗的stop模式,需要配置EXTI_line17来设置唤醒闹钟,然后才能唤醒stop模式。standby模式不需要设置EXTI_line17,可以直接通过void RTC_IRQHandler(void)中断函数实现唤醒,在配置好RTC的情况下,只需要在主函数加入下列程序即可。

    void huanxing(void)
    {
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP, ENABLE);
    PWR_BackupAccessCmd(ENABLE);
    RTC_SetAlarm(RTC_GetCounter()+50);
    RTC_WaitForLastTask();
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    PWR_WakeUpPinCmd(ENABLE);
    PWR_EnterSTANDBYMode();

    }

    周期唤醒函数,没过50S,RTC闹钟唤醒一次低功耗,该程序只需要加载主函数的最后即可。相当于运行完主函数的语句后,进入这个函数,函数会记录当前系统时,并进入低功耗的standby模式,在50后,唤醒低功耗,从新运行函数。如此周期下去。

    摘自小马哥

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-29 20:37 , Processed in 0.108721 second(s), 14 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.