RTC唤醒唤醒低功耗(standby)模式

这段时间在公司最一个低功耗的项目,采用的的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后,唤醒低功耗,从新运行函数。如此周期下去。

猜你喜欢

转载自blog.csdn.net/qq_35569806/article/details/80499093