高中生
最后登录1970-1-1
在线时间 小时
注册时间2014-5-5
|
STM32L151RC standby模式闹钟唤醒不成功,不知道什么原因了,
void Rtc_Init(void)
{
RTC_InitTypeDef RTC_InitStructure;
// Enable the PWR clock //
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
// Allow access to RTC //
PWR_RTCAccessCmd(ENABLE);
// Reset RTC Domain //
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
RCC_LSEConfig(RCC_LSE_ON);
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET){}
// Select the RTC Clock Source //
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0x7FFF;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
// Enable the RTC Clock //
RCC_RTCCLKCmd(ENABLE);
// Wait for RTC APB registers synchronisation //
RTC_WaitForSynchro();
RtcAlarm_Init();
}
void RtcAlarm_Init(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_Alarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC_ITConfig(RTC_IT_ALRA, DISABLE);
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
}
//闹钟测试函数
void SetnStartAlarmTest(uint16_t sec)
{
RTC_TimeTypeDef RTC_TimeStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_AlarmCmd(RTC_Alarm_A, DISABLE); //禁用Alarm
PWR_RTCAccessCmd(ENABLE);//启用访问RTC备份寄存器
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = RTC_TimeStructure.RTC_Hours;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = RTC_TimeStructure.RTC_Minutes;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = RTC_TimeStructure.RTC_Seconds+sec;
RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31;
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
主函数 这样调用的
int main(void)
{
RTC_TimeTypeDef RTC_TimeStruct;
RccHSI_Init();
// HardwareInit();
SysTick_Init();//systick
Rtc_Init();//rtc
RtcAlarm_Init();//alarm
StateLed_Init();//led
RTC_TimeStruct.RTC_Hours=0;
RTC_TimeStruct.RTC_Minutes=0;
RTC_TimeStruct.RTC_Seconds=0;
RTC_SetTime(RTC_Format_BIN,&RTC_TimeStruct);
STATELEDON();
SystickDelay(100);
STATELEDOFF();
SystickDelay(100);
RTC_GetTime(RTC_Format_BIN,&RTC_TimeStruct);
SetnStartAlarmTest(10);
while (1)
{
}
}
搞了 一整天了 ,没有一点眉目,,求助来了
|
|