Verify that the hardware clock keeps running through a power cycle without network time synchronization.
- Connect a 3.3 V-compatible DS3231 module to SDA, SCL, 3.3 V, and ground. It can share SDA and SCL with an SSD1306. The DS3231 uses
0x68, while the OLED typically uses0x3cor0x3d. - Confirm that
i2c-rtc.dtboexists on the boot partition. Add the following to the activeconfig.txtand reboot.
dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds3231
- Check that Linux registered an RTC and identify the DS3231 by name.
ls -l /dev/rtc*
cat /sys/class/rtc/rtc*/name
- Verify the system time and save it to the RTC. The example assumes the DS3231 is
/dev/rtc0.
sudo hwclock --rtc=/dev/rtc0 --systohc --utc
sudo hwclock --rtc=/dev/rtc0 --show --utc
- Shut down normally, disconnect main power, wait a few minutes, and boot offline. Check
hwclock --showto verify that the RTC kept time. Usedateseparately to check whether the boot process restored the system clock from the RTC.
Driver reading exercise
Follow the DS3231 Device Tree node to the rtc-ds1307 driver and see how the RTC subsystem exposes /dev/rtcN. For Yocto, include the kernel configuration, overlay, and a version of hwclock that supports the options used here.