打印

RTC 唤醒深度睡眠模式

[复制链接]
1103|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 小小蚂蚁举千斤 于 2023-6-23 17:32 编辑

一、RTC 自动唤醒
系统上电后,LED1 闪烁。当 Tamper 按键按下后,产生 EXTI 中断,在此中断中开启 RTC 自动唤醒功能;退出 EXTI 中断后,MCU 进入进入深度睡眠模式 1 且 LED1 停止闪烁。当自动唤醒时间到达后,产生 RTC 自动唤醒事件并将系统从深度睡眠模式 1 唤醒,LED 继续闪烁。由于事先开启了 RTC 自动唤醒中断,在唤醒后将进入 RTC 唤醒中断,在中断中关闭自动唤醒功能。
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);
/* EXTI line 20 configuration */
nvic_irq_enable(RTC_WKUP_IRQn, 2);
exti_flag_clear(EXTI_20);
exti_init(EXTI_20, EXTI_INTERRUPT, EXTI_TRIG_RISING);
rtc_flag_clear(RTC_STAT_WTF);
/* wakeup clock configuration */
rtc_wakeup_clock_set(WAKEUP_CKSPRE);
rtc_wakeup_timer_set(2);
rtc_interrupt_enable(RTC_INT_WAKEUP);
rtc_wakeup_disable();
}




使用特权

评论回复
沙发
小小蚂蚁举千斤|  楼主 | 2023-6-23 17:29 | 只看该作者
2. RTC 自动唤醒中断处理
void RTC_WKUP_IRQHandler(void)
{
if(RESET != rtc_flag_get(RTC_FLAG_WT)) {
/* clear EXTI line 20 pending and rtc wakeup flag */
rtc_flag_clear(RTC_FLAG_WT);
exti_flag_clear(EXTI_20);
/* disable rtc auto wakeup function */
rtc_wakeup_disable();
}
}
3. 按键中断处理
void EXTI10_15_IRQHandler(void)
{
if(SET == exti_interrupt_flag_get(EXTI_13)) {
/* clear EXTI line 13 pending flag */
exti_interrupt_flag_clear(EXTI_13);
enter_deepsleep_flag = 1;
/* enable RTC auto wakeup function */
rtc_wakeup_enable();
}
}


使用特权

评论回复
板凳
小小蚂蚁举千斤|  楼主 | 2023-6-23 17:31 | 只看该作者
本帖最后由 小小蚂蚁举千斤 于 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);
}




使用特权

评论回复
地板
小小蚂蚁举千斤|  楼主 | 2023-6-23 17:32 | 只看该作者
2. RTC 闹钟中断处理
void RTC_Alarm_IRQHandler(void)
{
if(RESET != rtc_flag_get(RTC_FLAG_ALARM0)) {
/* clear EXTI line 20 pending and rtc alarm flag */
rtc_flag_clear(RTC_FLAG_ALARM0);
exti_flag_clear(EXTI_17);
/* disable rtc alarm 0 function */
rtc_alarm_disable(RTC_ALARM0);
}
}



3. 按键中断处理
void EXTI10_15_IRQHandler(void)
{
if(SET == exti_interrupt_flag_get(EXTI_13)) {
/* clear EXTI line 13 pending flag */
exti_interrupt_flag_clear(EXTI_13);
enter_deepsleep_flag = 1;
/* update rtc alarm time*/
rtc_alarm_update(0x03);
}
}


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

196

主题

2037

帖子

1

粉丝