#include "stm32f1xx_hal.h" #include "rtc.h" #include "stm32fxx_STUclock.h" uint16_t clockTest_sysClockCount=0; /*配置RTC时钟源为LSI(40KHZ),分频后,计时基准频率1Khz,计时周期1ms*/ void STU_ClockTestInit(void) { RTC_AlarmTypeDef salarmstructure; /*配置闹钟前,清零计数寄存器*/ RTC_WriteTimeCounter(&hrtc,0); /*配置RTC 闹钟中断为100ms(1分40秒为100个计数,这里周期为1ms)*/ salarmstructure.Alarm = RTC_ALARM_A; salarmstructure.AlarmTime.Hours = 0x00; salarmstructure.AlarmTime.Minutes = 1; salarmstructure.AlarmTime.Seconds = 40; if(HAL_RTC_SetAlarm_IT(&hrtc,&salarmstructure,RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*清零计数寄存器,和计数*/ RTC_WriteTimeCounter(&hrtc,0); clockTest_sysClockCount = 0; } void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) { static uint16_t sysClockCount_tmp=0; //HAL_Delay (1); sysClockCount_tmp = clockTest_sysClockCount; if(sysClockCount_tmp < 75) { while(1); } if(sysClockCount_tmp > 125) { while(1); } RTC_WriteTimeCounter(hrtc,0); clockTest_sysClockCount = 0; }