代码如下
void Enter_StopMode(void)
{
EXIT_UART_Init();//RX引脚配置为外部中断
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR , ENABLE);//开电源管理时钟
RTC_Config();
RTC_AlarmConfig(); //POWER_LED(ON);
EXTI_ClearITPendingBit(EXTI_Line0); //清外部中断的标志
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); //进入休眠模式
RTC_ITConfig(RTC_IT_ALRA, DISABLE);
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
RCC_init(); USART2_COM2init(9600);
// EXTI_ClearITPendingBit(EXTI_Line0);
// RTC_ClearITPendingBit(RTC_IT_ALRA);
// EXTI_ClearITPendingBit(EXTI_Line17);
}
//LSI作为时钟源
void RTC_Config(void)
{
RTC_InitTypeDef RTC_InitStructure;
RTC_TimeTypeDef RTC_TimeStruct={0,0,0,RTC_H12_AM};
RTC_AlarmTypeDef sAlarm={{0,0,1,RTC_H12_AM},RTC_AlarmMask_DateWeekDay|RTC_AlarmMask_Hours|RTC_AlarmMask_Minutes,0,0};
// RTC_AlarmTypeDef sAlarm={{0,0,5,RTC_H12_AM},RTC_AlarmMask_All,0,0};
// RTC_TimeStruct RTC_AlarmTypeDef ;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
//PWR_BackupAccessCmd(ENABLE);
RCC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/**Initialize RTC and set the Time and Date
Configure the RTC data register and RTC prescaler */
RTC_InitStructure.RTC_AsynchPrediv = 0x18F;
RTC_InitStructure.RTC_SynchPrediv = 0x63;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
/* Set the time to 00h 00mn 00s AM */
// RTC_TimeStruct.RTC_H12 = RTC_H12_AM;
// RTC_TimeStruct.RTC_Hours = 0x00;
// RTC_TimeStruct.RTC_Minutes = 0x00;
// RTC_TimeStruct.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &sAlarm);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
}
void RTC_AlarmConfig(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* EXTI configuration */
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the RTC Alarm Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable AlarmA interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarm A */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
RTC_ClearITPendingBit(RTC_IT_ALRA);
EXTI_ClearITPendingBit(EXTI_Line17);
} |