Note: Related RTC basics not to mention here!
The library header file references:
![](https://img2018.cnblogs.com/i-beta/1353920/201912/1353920-20191202135821124-972959014.png)
RTC clock initialization related
Arduino version of the initial configuration of the library PWR clock, register clock initial configuration backup, backup reset register (RTC clock registers need to use the backup related stuff)
Official old standard library is the same:
RCC_APB1ENR setting register and the PWREN BKPEN bit clock and the backup power is turned on.
Enable write backup register
Arduino version in library, a write enable register backup operation power DBP could be related to the position in the register CR
In the old version of the standard library as well.
Power backup registers (PWR_CR) a DBP bit enables access to the backup registers and the RTC.
Disability write backup register
So easy to understand, disabling write backup register, the DBP is the 0 position.
Set RTC clock
Screenshot library code can be seen that, if the parameter is not written, then the default RTClock (RTCSEL_HSE); external high speed clock to clock the RTC.
I code, the LSE is selected, that is, the low-speed external clock as the clock source.
rtc_init (); function implemented in the clock setting and a respective opening.
Write RTC time
time_t type is unsigned long type.
Track rtc_set_count () ; function:
The function where the file:
Waiting for the last synchronization completed the RTC registers
Wait for the last write operation is completed the RTC
RTC into the source configuration mode:
Waiting for the write operation is completed, the RTC configuration CNF CRL register bits.
Since then the red line, so the above rtc_set_count function will have to enter configuration mode and exit configuration mode of supporting statement.
Read RTC time
Source as follows:
Targeting rtc_get_count (); function:
It is simply read out the count value of the RTC register returns combined.
Creating RTC alarm interrupt
There are several RTC alarm, one is the second clock, once every one second to enter; One is to compare the alarm time, to a time point generated the alarm.
The following is a comparison of alarm set time source:
追踪到rtc_set_alarm()函数:
前三句话和配置模式老生常谈。
后面是设置闹钟寄存器的值。
下面追踪到rtc_attach_interrupt函数:
使能闹钟中断,switch里是第四个case。再使能闹钟优先级。
设置RTC闹钟时间
顾名思义,可以修改RTC的闹钟时间。注意:该函数是修改,并不会创建闹钟中断。
解除RTC闹钟中断
失能RTC闹钟中断,并将中断处理函数给注销。