高级会员

- 积分
- 523
- 金钱
- 523
- 注册时间
- 2016-1-7
- 在线时间
- 131 小时
|
5金钱
STM32F030C8T6,想弄一个RTC定时唤醒STOP的例程,不知道怎么弄,以下是RCC的程序
void RTC_Config(void)
{
RTC_TimeTypeDef RTC_TimeStructure;
RTC_InitTypeDef RTC_InitStructure;
/* RTC Configuration **********************************************************/
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* Reset back up registers */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
/* Enable the LSE */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Set RTC calendar clock to 1 HZ (1 second) */
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStructure.RTC_AsynchPrediv = 0x7F-1;
RTC_InitStructure.RTC_SynchPrediv = 0x1fff-1;
if (RTC_Init(&RTC_InitStructure) == ERROR)
{
while(1);
}
/* Set the time to 01h 00mn 00s AM */
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0x01;
RTC_TimeStructure.RTC_Minutes = 0x00;
RTC_TimeStructure.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
}
void RTC_AlarmConfig(void)
{
RTC_TimeTypeDef RTC_TimeStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* EXTI configuration */
EXTI_ClearITPendingBit(EXTI_Line17);//清除外部中断,RTC中断函数里面每次都要清除
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=0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_8);
/* Get current time */
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
/* Enable the RTC Alarm A interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarm */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
/* Clear the Alarm A Pending Bit */
RTC_ClearITPendingBit(RTC_IT_ALRA);
}
以下问问饿你中断函数
void RTC_IRQHandler(void)
{
if (RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
/* Clear the Alarm A Pending Bit */
RTC_ClearITPendingBit(RTC_IT_ALRA);
temp1++;
}
EXTI_ClearITPendingBit(EXTI_Line17);
}
|
|