本帖最后由 小小蚂蚁举千斤 于 2023-6-23 17:33 编辑
二、RTC 闹钟唤醒
系统上电后,LED1 闪烁。当 Tamper 按键按下后,产生 EXTI 中断,在此中断中更新 RTC 闹钟时间并开启闹钟功能;退出 EXTI 中断后,MCU 进入进入深度睡眠模式 1 且 LED1 停止闪烁。当闹钟时间到达后,产生 RTC 闹钟事件并将系统从深度睡眠模式 1 唤醒,LED 继续闪烁。。由于事先开启了 RTC 闹钟 0 中断,在唤醒后将进入 RTC 闹钟中断,在中断中关闭闹钟0 功能。
RTC 闹钟唤醒相关配置如下:
1. RTC 闹钟唤醒配置
void rtc_configuration(void)
{
rtc_parameter_struct rtc_initpara;
__IO uint32_t prescaler_a = 0x7F, prescaler_s = 0xFF;
/* enable PMU and BKPI clocks */
rcu_periph_clock_enable(RCU_PMU);
rcu_periph_clock_enable(RCU_BKP);
/* allow access to BKP domain */
pmu_backup_write_enable();
rcu_periph_clock_enable(RCU_RTC);
/* enable LXTAL */
rcu_osci_on(RCU_LXTAL);
/* wait for LXTAL stabilization flag */
rcu_osci_stab_wait(RCU_LXTAL);
rcu_lxtal_clock_monitor_enable();
/* configure the RTC clock source selection */
rcu_rtc_clock_config(RCU_RTCSRC_LXTAL);
rtc_register_sync_wait();
/* setup RTC time value */
rtc_initpara.factor_asyn = prescaler_a;
rtc_initpara.factor_syn = prescaler_s;
rtc_initpara.year = 0x16;
rtc_initpara.day_of_week = RTC_WEDNESDAY;
rtc_initpara.month = RTC_SEP;
rtc_initpara.date = 0x07;
rtc_initpara.display_format = RTC_24HOUR;
rtc_initpara.am_pm = RTC_AM;
rtc_initpara.hour = 0x09;
rtc_initpara.minute = 0x28;
rtc_initpara.second = 0;
rtc_init(&rtc_initpara);
/* RTC alarm configuration */
rtc_alarm_struct rtc_alarm;
rtc_alarm_disable(RTC_ALARM0);
rtc_alarm.alarm_mask = RTC_ALARM_DATE_MASK | RTC_ALARM_HOUR_MASK |
RTC_ALARM_MINUTE_MASK;
rtc_alarm.weekday_or_date = RTC_ALARM_DATE_SELECTED;
rtc_alarm.alarm_day = 0x31;
rtc_alarm.am_pm = RTC_AM;
rtc_alarm.alarm_hour = 0x09;
rtc_alarm.alarm_minute = 0x28;
rtc_alarm.alarm_second = 0x00;
rtc_alarm_config(RTC_ALARM0, &rtc_alarm);
/* EXTI line 17 configuration */
nvic_irq_enable(RTC_Alarm_IRQn, 0);
exti_flag_clear(EXTI_17);
exti_init(EXTI_17, EXTI_INTERRUPT, EXTI_TRIG_RISING);
rtc_flag_clear(RTC_STAT_ALRM0F);
/* enable alram 0 interrupt */
rtc_interrupt_enable(RTC_INT_ALARM0);
rtc_alarm_disable(RTC_ALARM0);
}
|