Skip to main content

Real Time Clock

The Real Time Clock (RTC) is a circuit that runs off a small battery or a super capacitor connected to VBAT. It needs its own crystal and keeps running even when the main system and its clocks are powered off.

using var rtc = new RtcController();

var time = new DateTime(2024, 1, 1, 10, 59, 50, DateTimeKind.Utc);
rtc.DateTime = time;

// Read some time later
var rtc_time = rtc.DateTime;

VBAT​

VBAT mode can be set in "charger mode" where it can charge an attached supercap.

info

Make sure the RTC battery charge mode is correctly set. Charging a lithium coin cell may cause damage to the cell and could cause it to leak.

using var rtc = new RtcController();

rtc.SetChargeMode(BatteryChargeMode.Fast);

System clock​

The system clock is seeded from the RTC at boot: once the RTC is set and VBAT keeps it running, DateTime.Now (or the equivalent Python / C++ clock) returns the right time on every subsequent boot without any extra setup. Set the RTC once:

using var rtc = new RtcController();
if (!rtc.IsValid) {
rtc.DateTime = new DateTime(2024, 1, 30, 15, 0, 0, DateTimeKind.Utc);
}