What is an RTC and how is backup domain power used?
Short answer: A Real-Time Clock is a low-power timer that keeps the calendar time (seconds, minutes, hours, date), usually driven by a 32.768 kHz crystal. It sits in a backup domain that can be powered from a separate VBAT pin (coin cell, supercapacitor) so it keeps running, along with a few backup registers, when the main supply is off. It also provides alarms and periodic wake-ups from low-power modes.
Why 32.768 kHz: 32,768 = 2¹⁵, so a 15-stage binary divider produces exactly 1 Hz. The crystals are small, cheap and consume very little power (the oscillator uses well under 1 µA).
Features
- Calendar in BCD or a binary second counter (sub-second resolution on many parts).
- Alarms that wake the MCU from stop or standby.
- Periodic wake-up timer for duty-cycled devices (e.g. measure every 10 minutes).
- Tamper detection inputs and timestamping (security products).
- Backup registers or backup SRAM: small storage kept on VBAT, useful for boot flags, reset counters, or the last known state.
- Smooth calibration: adjusts for crystal error in ppm.
Accuracy: a typical crystal is ±20 ppm, which is about ±1.7 seconds per day (≈ 52 s per month). Temperature changes make it worse (tuning-fork crystals drift quadratically away from 25 °C). Improve it with calibration against a reference, temperature compensation, or synchronising from GPS/NTP/cellular network time.
Design points
- Write-protect: RTC registers are usually locked; you must unlock the backup domain (e.g.
PWR->CR1 |= PWR_CR1_DBPon STM32) to change them. - The first time power is applied, detect that the RTC is not initialised (a magic value in a backup register) and set it.
- Use UTC internally and apply time zones in the application.
- If there is no battery, the time is lost on power loss; plan to get it from the network.
External RTC chips (DS3231, PCF85063, RV-3028) are used when the MCU lacks a good RTC or for very low backup current and temperature-compensated accuracy.