原本准备测试一下GD32L233的RTC定时唤醒和低功耗状态,发现芯片供电由AMS1117提供,没有可断开的位置,而且还接有USB转串口芯片CH340,不太方便测量实际功耗情况,先把RTC的例程放上来。
1、接上一例程,增加初始化RTC函数
void gd_start_rtc_init(void)
{
/* setup RTC time value */
uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF;
rcu_periph_clock_enable(RCU_PMU);
rcu_periph_clock_enable(RCU_BKP);
pmu_backup_write_enable();
rtc_pre_config();
if(BKP_VALUE == RTC_BKP0)
{
/* detect the reset source */
if(RESET != rcu_flag_get(RCU_FLAG_PORRST))
{
printf("\n\rpower on reset occurred....");
}
else if(RESET != rcu_flag_get(RCU_FLAG_EPRST))
{
printf("\n\rexternal reset occurred....");
}
printf("\n\rno need to configure RTC....");
//rtc_flag_clear(RTC_STAT_ALRM0F);
//exti_flag_clear(EXTI_17);
rtc_show_time();
rtc_show_alarm();
}
else
{
rtc_initpara.factor_asyn = prescaler_a;
rtc_initpara.factor_syn = prescaler_s;
rtc_initpara.year = 0x16;
rtc_initpara.day_of_week = RTC_SATURDAY;
rtc_initpara.month = RTC_APR;
rtc_initpara.date = 0x30;
rtc_initpara.display_format = RTC_24HOUR;
rtc_initpara.am_pm = RTC_AM;
/* current time input */
printf("\n\r=======Configure RTC Time========");
printf("\n\r please input hour:");
while(tmp_hh == 0xFF)
{
tmp_hh = usart_input_threshold(23);
rtc_initpara.hour = tmp_hh;
}
printf("\n\r %0.2x", tmp_hh);
printf("\n\r please input minute:");
while(tmp_mm == 0xFF)
{
tmp_mm = usart_input_threshold(59);
rtc_initpara.minute = tmp_mm;
}
printf("\n\r %0.2x", tmp_mm);
printf("\n\r please input second:");
while(tmp_ss == 0xFF)
{
tmp_ss = usart_input_threshold(59);
rtc_initpara.second = tmp_ss;
}
printf("\n\r %0.2x", tmp_ss);
/* RTC current time configuration */
if(ERROR == rtc_init(&rtc_initpara))
{
printf("\n\r** RTC time configuration failed! **");
}
else
{
printf("\n\r** RTC time configuration success! **");
rtc_show_time();
RTC_BKP0 = BKP_VALUE;
}
/* setup RTC alarm */
tmp_hh = 0xFF;
tmp_mm = 0xFF;
tmp_ss = 0xFF;
rtc_alarm_disable(RTC_ALARM0);
printf("\n\r=======Input Alarm Value=======");
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 input */
printf("\n\r please input Alarm Hour:");
while(tmp_hh == 0xFF)
{
tmp_hh = usart_input_threshold(23);
rtc_alarm.alarm_hour = tmp_hh;
}
printf("\n\r %0.2x", tmp_hh);
printf("\n\r Please Input Alarm Minute:");
while(tmp_mm == 0xFF)
{
tmp_mm = usart_input_threshold(59);
rtc_alarm.alarm_minute = tmp_mm;
}
printf("\n\r %0.2x", tmp_mm);
printf("\n\r Please Input Alarm Second:");
while(tmp_ss == 0xFF)
{
tmp_ss = usart_input_threshold(59);
rtc_alarm.alarm_second = tmp_ss;
}
printf(" %0.2x", tmp_ss);
/* RTC alarm configuration */
rtc_alarm_config(RTC_ALARM0, &rtc_alarm);
printf("\n\r** RTC Set Alarm Success! **");
rtc_show_time();
rtc_show_alarm();
rtc_interrupt_enable(RTC_INT_ALARM0);
//rtc_interrupt_enable(RTC_INT_TIMESTAMP);
rtc_alarm_enable(RTC_ALARM0);
}
rtc_flag_clear(RTC_STAT_ALRM0F);
exti_flag_clear(EXTI_17);
exti_init(EXTI_17, EXTI_INTERRUPT, EXTI_TRIG_RISING);
//exti_interrupt_flag_clear(EXTI_17);
exti_interrupt_enable(EXTI_17);
nvic_irq_enable(RTC_Alarm_IRQn, 0);
}
2、配置唤醒中断,间隔时间5秒
rtc_wakeup_disable();
rtc_wakeup_clock_set(WAKEUP_CKSPRE);
rtc_wakeup_timer_set(5);
rtc_flag_clear(RTC_STAT_WTF);
rtc_interrupt_enable(RTC_INT_WAKEUP);
rtc_wakeup_enable();
exti_flag_clear(EXTI_20);
exti_init(EXTI_20, EXTI_INTERRUPT, EXTI_TRIG_RISING);
exti_interrupt_enable(EXTI_20);
nvic_irq_enable(RTC_WKUP_IRQn, 0);
3、按下按键后,休眠前串口打印进入休眠前的时间,关闭LED,配置进入休眠的模式。唤醒后需要重新初始化系统时钟,再打印唤醒后的时间。
rtc_show_time();
printf("\nPower Down!");
delay_1ms(10);
gd_start_led_off(LED1);
gd_start_led_off(LED2);
gd_start_led_off(LED3);
gd_start_led_off(LED4);
dbg_low_power_enable(DBG_LOW_POWER_SLEEP);
pmu_to_deepsleepmode(PMU_LDNPDSP_LOWDRIVE, WFI_CMD, PMU_DEEPSLEEP);
SystemInit();
delay_1ms(10);
rtc_show_time();
printf("\nWake Up!");
4、串口打印信息
5、例程代码
GD32L23x_Firmware_Library_V1.0.0.rar
(2.67 MB, 下载次数: 99)
|