中级会员
 
- 积分
- 297
- 金钱
- 297
- 注册时间
- 2016-8-10
- 在线时间
- 51 小时
|
1金钱
#include "RTC.h"
void RTC_Configuration(void)
{
/*EnablePWRandBKPclocks*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP,ENABLE);
/*AllowaccesstoBKPDomain*/
PWR_BackupAccessCmd(ENABLE);
/*ResetBackupDomain*/
BKP_DeInit();
/*EnableLSE*/
RCC_LSICmd(ENABLE);
/*WaittillLSEisready*/
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY)==RESET)
{}
/*SelectLSEasRTCClockSource*/
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/*EnableRTCClock*/
RCC_RTCCLKCmd(ENABLE);
/*WaitforRTCregisterssynchronization*/
RTC_WaitForSynchro();
/*WaituntillastwriteoperationonRTCregistershasfinished*/
RTC_WaitForLastTask();
/*SetRTCprescaler:setRTCperiodto1sec*/
RTC_SetPrescaler(40000);
RTC_WaitForLastTask();
/*EnabletheRTCALARM*/
RTC_ITConfig(RTC_IT_ALR,ENABLE);
/*WaituntillastwriteoperationonRTCregistershasfinished*/
RTC_WaitForLastTask();
}
void RTC_Initializes(uint32_t wake_up)
{
if( wake_up <5 ) wake_up = 5; //5s
if( wake_up > 24*3600 ) wake_up = 24*3600; //24h
RTC_Configuration();
RTC_SetCounter(0);
RTC_WaitForLastTask();
RTC_SetAlarm(wake_up);//唤醒时间
RTC_WaitForLastTask();
RTC_NVIC_Config();
RTC_Alarm_EXIT();
}
void RTC_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; //闹钟中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //比RTC全局中断的优先级高
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void RTC_Alarm_EXIT(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void
App_cpu_sleep(uint32_t wake_up)
{
RTC_Initializes(wake_up);
Befor_goto_Standby();
//PWR_EnterSTANDBYMode();
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFE);//STOP模式
}
void Befor_goto_Standby(void)
{
uint32_t pin = 1;
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_7);
pin= GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_7);
}
这是我写的代码,为什么停止时候电流能达到7mA呢
|
|