工程文件:
https://download.csdn.net/download/qq_44179528/19142503
https://download.csdn.net/download/qq_44179528/19135126
main.c内:
while(1):
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); //获取时间
get_time();
printf("%d %d %d\r\n",sTime.Hours,sTime.Minutes,sTime.Seconds);
HAL_Delay(1000);
get_time();
printf("%d %d %d\r\n",sTime.Hours,sTime.Minutes,sTime.Seconds);
HAL_Delay(1000);
get_time();
printf("%d %d %d\r\n",sTime.Hours,sTime.Minutes,sTime.Seconds);
HAL_Delay(1000);
/* Enable GPIOs clock */
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */
/* Note: Debug using ST-Link is not possible during the execution of this */
/* example because communication between ST-link and the device */
/* under test is done through UART. All GPIO pins are disabled (set */
/* to analog input mode) including UART I/O pins. */
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
/* Disable GPIOs clock */
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
//由于使用电容触摸芯片,芯片输出的引脚是高电平,因此设置成为上拉输出模式可以减小IO的电流
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);//
__HAL_RCC_GPIOA_CLK_DISABLE();
/* For power consumption's sake, appropriately configure the GPIO corresponding to
the wake-up pin, fill up the pull-down control register and set the APC bit. */
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_0;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_NOPULL;
//GPIO_NOPULL
//GPIO_PULLDOWN
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
HAL_PWREx_EnablePullUpPullDownConfig();
/* Disable used wakeup source: PWR_WAKEUP_PIN1 */
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
/* Clear all related wakeup flags */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* Enable wakeup pin WKUP1 */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
/** Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = sTime.Hours;
sAlarm.AlarmTime.Minutes = sTime.Minutes+1;
sAlarm.AlarmTime.Seconds = 0;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_HOURS|RTC_ALARMMASK_MINUTES;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
{
Error_Handler();
}
HAL_PWR_EnterSTANDBYMode();//进入低功耗待机模式
最后注释掉RTC初始化的时钟和闹钟时间: