STM32RTC
使用步骤:
打开
PWR
时钟和
Backup
区数据访问
若使用外部低速时钟(
LSE
)
,打开
LSE
并等待起振
选择和打开
RTC
时钟,等待时钟同步
配置时间格式,分频系数等
根据需要配置时钟,日期,闹钟,唤醒,输出,时间戳,备份寄存器等模块
根据需要配置和打开中断,其中
RTC Alarm
——
EXTI line 17
RTC tamper and TImestamps
——
EXTI line 19
RTC wakeup
——
EXTI line 20
下面的代码配置日期,时间,当前时间设置为
15
年
05
月
31
日,星期日(
7
)
,
15:50:40
,
打开闹钟
A
和唤醒中断,每一秒钟来一次中断,
15:50:45
秒产生闹钟中断,用串口打印相
应的信息。
代码:
void RTC_Config
(
void
)
{
RTC_TImeTypeDef RTC_TimeStructure;
RTC_DateTypeDef RTC_DateStructure;
RTC_InitTypeDef RTC_InitStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
RCC_APB1PeriphClockCmd
(
RCC_APB1Periph_PWR
,
ENABLE
)
;
PWR_BackupAccessCmd
(
ENABLE
)
;
RCC_BackupResetCmd
(
ENABLE
)
;
RCC_BackupResetCmd
(
DISABLE
)
;
RCC_LSEConfig
(
RCC_LSE_ON
)
;