现象描述:RTC AlarmA 不进Standby模式,设置成一分钟闹铃一次,没问题,加长Standby,无法唤醒
主函数:
int main(void)
{
u8 t = 0;
u8 cnt = 0;
char tbuf[40];
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
HAL_Init();
SystemClock_Config(); //3õê¼»ˉÏμí3ê±ÖóÎa80M
delay_init(80); //3õê¼»ˉÑóê±oˉêy 80MÏμí3ê±Öó
uart_init(115200); //3õê¼»ˉ′®¿ú£¬2¨ìØÂêÎa115200
usmart_dev.init(80); //3õê¼»ˉUSMART 80MÏμí3ê±Öó
LED_Init(); //3õê¼»ˉLED
BEEP_Init(); //3õê¼»ˉBEEP
LCD_Init(); //3õê¼»ˉLCD
RTC_Init(); //3õê¼»ˉRTC
RTC_Set_AlarmA(0, 0, 0, 5); //
RTC_Set_WakeUp(RTC_WAKEUPCLOCK_CK_SPRE_16BITS, 0); //ÅäÖÃWAKE UPÖD¶Ï,1ÃëÖóÖD¶Ïò»′Î
POINT_COLOR = RED;
Display_ALIENTEK_LOGO(0, 0);
LCD_ShowString(30, 95, 200, 16, 16, "Pandora STM32L4 IOT");
LCD_ShowString(30, 115, 200, 16, 16, "RTC TEST");
LCD_ShowString(30, 135, 200, 16, 16, "ATOM@ALIENTEK");
LCD_ShowString(30, 155, 200, 16, 16, "2018/10/27");
POINT_COLOR = BLUE;
while(1)
{
t++;
if((t % 10) == 0) //ÿ100ms¸üDÂò»′ÎÏÔê¾êy¾Y
{
HAL_RTC_GetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN);
sprintf((char*)tbuf, "Time:%02d:%02d:%02d", RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds);
LCD_ShowString(30, 175, 210, 16, 16, tbuf);
HAL_RTC_GetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN);
sprintf((char*)tbuf, "Date:20%02d-%02d-%02d", RTC_DateStruct.Year, RTC_DateStruct.Month, RTC_DateStruct.Date);
LCD_ShowString(30, 195, 210, 16, 16, tbuf);
sprintf((char*)tbuf, "Week:%d", RTC_DateStruct.WeekDay);
LCD_ShowString(30, 215, 210, 16, 16, tbuf);
}
if( BEEP_Read ) //ÄÖÖóμ½ê±£¬·äÃùÆ÷Ïì1Soóí£Ö1
{
cnt++;
if(cnt>=100) {BEEP(0);cnt=0;}
}
if((t % 20) == 0)LED_R_TogglePin; //ÿ200ms,·-×aò»′ÎLED_R
delay_ms(10);
Sys_Enter_Standby();
}
}
void RTC_Set_AlarmA(u8 week, u8 hour, u8 min, u8 sec)
{
RTC_AlarmTypeDef RTC_AlarmSturuct;
RTC_AlarmSturuct.AlarmTime.Hours = hour; //D¡ê±
RTC_AlarmSturuct.AlarmTime.Minutes = min; //·ÖÖó
RTC_AlarmSturuct.AlarmTime.Seconds = sec; //Ãë
RTC_AlarmSturuct.AlarmTime.SubSeconds = 0;
RTC_AlarmSturuct.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
RTC_AlarmSturuct.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES;//¾«è·Æ¥ÅäDÇÆú£¬ê±·ÖÃë;RTC_ALARMMASK_NONE; //¾«è·Æ¥ÅäDÇÆú£¬ê±·ÖÃë
RTC_AlarmSturuct.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
RTC_AlarmSturuct.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY; //°′DÇÆú
RTC_AlarmSturuct.AlarmDateWeekDay = week; //DÇÆú
RTC_AlarmSturuct.Alarm = RTC_ALARM_A; //ÄÖÖóA
HAL_RTC_SetAlarm_IT(&RTC_Handler, &RTC_AlarmSturuct, RTC_FORMAT_BIN);
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0x01, 0x02); //ÇàÕ¼óÅÏ輶1,×óóÅÏ輶2
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
}
void Sys_Enter_Standby(void)
{
__HAL_RCC_AHB2_FORCE_RESET(); //¸′λËùóDIO¿ú
__HAL_RCC_PWR_CLK_ENABLE(); //ê1ÄüPWRê±Öó
__HAL_RCC_BACKUPRESET_FORCE(); //¸′λ±¸·YÇøóò
HAL_PWR_EnableBkUpAccess(); //oó±¸Çøóò·ÃÎêê1Äü
//STM32F4,μ±¿aÆôáËRTCÏà1ØÖD¶Ïoó,±ØDëÏè1رÕRTCÖD¶Ï,ÔùÇåÖD¶Ï±ê־λ,è»oóÖØDÂéèÖÃ
//RTCÖD¶Ï,Ôù½øèë′y»úÄ£ê½2Å¿éòÔÕy3£»½DÑ,·ñÔò»áóDÎêìa.
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
__HAL_RTC_WRITEPROTECTION_DISABLE(&RTC_Handler);//1رÕRTCD′±£»¤
//1رÕRTCÏà1ØÖD¶Ï£¬¿éÄüÔúRTCêμÑé′ò¿aáË
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&RTC_Handler,RTC_IT_WUT);
__HAL_RTC_TIMESTAMP_DISABLE_IT(&RTC_Handler,RTC_IT_TS);
__HAL_RTC_ALARM_DISABLE_IT(&RTC_Handler,RTC_IT_ALRA|RTC_IT_ALRB);
//Çå3yRTCÏà1ØÖD¶Ï±ê־λ
__HAL_RTC_ALARM_CLEAR_FLAG(&RTC_Handler,RTC_FLAG_ALRAF|RTC_FLAG_ALRBF);
__HAL_RTC_TIMESTAMP_CLEAR_FLAG(&RTC_Handler,RTC_FLAG_TSF);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&RTC_Handler,RTC_FLAG_WUTF);
__HAL_RCC_BACKUPRESET_RELEASE(); //±¸·YÇøóò¸′λ½áêø
__HAL_RTC_WRITEPROTECTION_ENABLE(&RTC_Handler); //ê1ÄüRTCD′±£»¤
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); //Çå3yWake_UP±êÖ¾
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2); //éèÖÃWKUPóÃóú»½DÑ
HAL_PWR_EnterSTANDBYMode(); //½øèë′y»úÄ£ê½
}
一周热门 更多>