STM32 - RTC real-time clock (rookie notes)

        The RTC real-time clock of STM32 is an independent timer. Under the corresponding software configuration, the function of clock and calendar can be provided. Modifying the value of the counter can reset the current time and date of the system.
        The RTC module and the clock configuration system (RCC_BDCR register ) are in the backup area, that is, after a system reset or wake-up from standby mode, the RTC settings and time remain unchanged. After a system reset, access to the backing registers and RTC is disabled to prevent accidental writes to the backing area (BKP) . Perform the following operations to enable access to the backup registers and RTC : ● Set
    
the PWREN and BKPEN bits in register RCC_APB1ENR to enable the power supply and backup interface clock     ● Set the DBP bit of register PWR_CR to enable access to the backup registers and RTC .


Its block diagram is as follows:
Mainly divided into two modules:

1. Prescaler module ( programmable to generate RTC time base TR_CLK up to 1 second )

    If the corresponding enable bit is set in RTC_CR, a second interrupt is generated in each TR_CLK cycle

2. Programmable counter

    RTC_CNT is accumulated according to the TR_CLK cycle and can be compared with RTC-ALR. If the corresponding enable bit is set in the RTC_CR control register, an alarm clock interrupt will be generated when the comparison is matched .

RTC configuration steps:

1. Enable power clock and backup area clock

2. Cancel the write protection of the backup area

3. Reset the backup area and turn on the external low-speed oscillator

4. Select RTC clock and enable (select external LSE as RTC clock)

5. Set the frequency division of the RTC and configure the RTC clock

6. Update the configuration and set the RTC interrupt grouping

7 Write an interrupt service function



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324915171&siteId=291194637