温度定时采集,采集完后进入低功耗睡眠模式。然后由RTC产生闹钟中断,每一分钟唤醒一次。
配置RTC
rtc详细属性如下:
配置 r_lpm
General->Low Power Mode选择 Deep Softwoare Standby mode
Deep Standby Options -> Cance Sources - RTC Alarm
然后配置串口等(在原来hs3003的基础上配置)【RA4M2设计挑战赛】HS3003读取数据 - 瑞萨单片机论坛 - 电子技术论坛 - 广受欢迎的专业电子论坛! (elecfans.com)
生成代码后,在hal_entry.c中增加如下代码:
fsp_err_t err = FSP_SUCCESS;
extern volatile bool e31_send_complete_flag;
rtc_time_t set_time =
{
.tm_sec = 0,
.tm_min = 30,
.tm_hour = 12,
.tm_mday = 20,
.tm_mon = 11,
.tm_year = 121,
.tm_wday = 5,
};
rtc_alarm_time_t set_alarm_time =
{
.time.tm_sec = 1,
.time.tm_sec = 59,
.time.tm_min = 59,
.time.tm_hour = 23,
.time.tm_mday = 31,
.time.tm_mon = 11,
.time.tm_year = 199,
.time.tm_wday = 6,
.sec_match = 1,
.min_match = 0,
.hour_match = 0,
.mday_match = 0,
.mon_match = 0,
.year_match = 0,
.dayofweek_match = 0,
};
volatile bool rtc_flag = 0;
volatile bool rtc_alarm_flag = 0;
void rtc_callback(rtc_callback_args_t* p_args)
{
if(p_args->event == RTC_EVENT_PERIODIC_IRQ)
rtc_flag = 1;
else if(p_args->event == RTC_EVENT_ALARM_IRQ)
rtc_alarm_flag = 1;
}
void hal_entry(void)
{
uint8_t hs_rxbuf[8];
uint8_t rtc_second = 0;
uint8_t rtc_minute = 0;
uint8_t rtc_hour = 0;
uint8_t rtc_day = 0;
uint8_t rtc_month = 0;
uint16_t rtc_year = 0;
uint8_t rtc_week = 0;
rtc_time_t get_time;
R_BSP_PinAccessEnable();
if (1U == R_SYSTEM->RSTSR0_b.DPSRSTF)
{
R_LPM_IoKeepClear (NULL);
R_SYSTEM->RSTSR0_b.DPSRSTF = 0;
if (R_SYSTEM->DPSIFR1 >> 1 & 0x01U)
{
printf("MCU is woke up by IRQ-9\r\n");
}
else if (R_SYSTEM->DPSIFR1 >> 2 & 0x01U)
{
printf("MCU is woke up by IRQ-10\r\n");
}
}
R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
bsp_uart_init();
E31_uart_init();
err = R_RTC_Open(&g_rtc0_ctrl, &g_rtc0_cfg);
assert(FSP_SUCCESS == err);
R_RTC_CalendarTimeSet(&g_rtc0_ctrl, &set_time);
R_RTC_CalendarAlarmSet(&g_rtc0_ctrl, &set_alarm_time);
printf("start..\r\n");
set_e31_M1();
while(1)
{
#if DEBUG
R_RTC_CalendarTimeGet(&g_rtc0_ctrl, &get_time);
rtc_flag=0;
rtc_second=get_time.tm_sec;
rtc_minute=get_time.tm_min;
rtc_hour=get_time.tm_hour;
rtc_day=get_time.tm_mday;
rtc_month=get_time.tm_mon;
rtc_year=get_time.tm_year;
rtc_week=get_time.tm_wday;
printf(" %d y %d m %d d %d h %d m %d s %d w\n",rtc_year+1900,rtc_month,rtc_day,rtc_hour,rtc_minute,rtc_second,rtc_week);
printf("/************************Alarm Clock********************************/\n");
#endif
set_e31_M0();
getdata_hs3003(hs_rxbuf);
R_BSP_SoftwareDelay(20, BSP_DELAY_UNITS_MILLISECONDS);
#if DEBUG
printf("temp: %X,%X,%X,%X,%X\n", hs_rxbuf[2], hs_rxbuf[3], hs_rxbuf[4], hs_rxbuf[5], hs_rxbuf[6]);
#endif
hs_rxbuf[0] = 0x5A;
hs_rxbuf[1] = 0xA5;
R_SCI_UART_Write(&E31_uart_ctrl, hs_rxbuf, 7);
R_BSP_SoftwareDelay(20, BSP_DELAY_UNITS_MILLISECONDS);
#if DEBUG
if(e31_send_complete_flag == true)
{
printf("发送成功\n");
e31_send_complete_flag = false;
}
else
printf("发送失败\n");
#endif
set_e31_M1();
printf("MCU enters Deep SW Standby mode\r\n");
R_LPM_Open (Deep_SW_Standby.p_ctrl, Deep_SW_Standby.p_cfg);
R_LPM_LowPowerModeEnter (Deep_SW_Standby.p_ctrl);
printf("MCU has been woken up without reset\r\n");
}
#if BSP_TZ_SECURE_BUILD
R_BSP_NonSecureEnter();
#endif
}
下载到开发板后,每隔1分钟唤醒一次,采集数据,采集、发送完成后,对E31进行配置使其进入睡眠模式,然后主芯片也进入睡眠模式。
效果:进入睡眠模式后测得的待电流为6mA(备注开发板去除了5V电源、CH340G的供电)。没有达到微安级别的待机电流。各位大佬如果有好方法,请告之。