I bought a DS3231, connected it, and restarted my pi.
How can I confirm that the module is working correctly and the systemclock would read its time?
I'm running Raspian (latest version).
I have enabled I2C under raspi-config -> Interfaces
I have inserted dtoverlay=i2c-rtc,ds3231 after [all] in /boot/firmware/config.txt
After that I have disabled and stopped fake-hwclock.
And of course I have rebooted.
timedatectl is given me now following:
pi@pihole:~ $ timedatectl status
Local time: Thu 2025-01-30 10:15:49 CET
Universal time: Thu 2025-01-30 09:15:49 UTC
RTC time: Thu 2025-01-30 09:15:49
Time zone: Europe/Berlin (CET, +0100)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
I can also get the time with hwclock -r.
But I don't know if that was all. I don't know if I need to configure more for it to work correctly or does the read of the rtc clock happen automatically at boot now?
I think you're almost there, missing only the part to sync on reboot.
I've chosen to do so via udev rules.
These are the instructions I've used to install a DS3231 on one of my Zeros (click for details)
# enable rtc support
sudo nano /boot/config.txt
dtoverlay=i2c-rtc,ds3231
# reboot after change
# optional: verify rtc
ls -lah /dev/rtc*
#optional: verify current rtc time
sudo hwclock -r && date
# CAUTION: only run if rtc not set or not accurate
#optional: write current systime to rtc
sudo hwclock -w
# disable fake-hwclock
sudo systemctl stop fake-hwclock.service
sudo systemctl disable fake-hwclock.service
# set systime from rtc at system start
sudo nano /etc/udev/rules.d/42-rtc-sync.rules
ACTION=="add", SUBSYSTEM=="rtc", ATTRS{hctosys}=="0", RUN+="/sbin/hwclock --hctosys --utc"
# reboot afterwards
# optional: verify time
timedatectl status
On what kind of RPi are you running your RTC?
In case that'd be an RPi 5: That features an onboard RTC (but still lacks a backup battery, to be acquired separately).
I can't tell whether that may conflict with a separate DS3231, and whether and how the latest RPi OS may automatically apply RTC syncing, perhaps even for third-party RTCs.
If that would be the case, you probably wouldn't need udev rules - but that's pure speculation on my behalf.
Nevertheless, you should be able to verify whether RTC syncing works already by simply powering down your RPi for a longer period (say e.g. some two hours, or a day).
If you power it back on without network access, and timedatectl shows accurate times before NTP time syncs succeed, then at least time is read from RTC and stored in the system clock at boot time.