MCP79410 RTC on Raspberry Pi

by | March 17, 2017

I’ve been using MCP79410 RTC chip with Raspberry Pi for a few years. In the pre-systemd version of Raspbian there was an init.d script hwclock.sh which took care of synchronizing time. On systemd it is different.

Raspbian now uses Device Tree (DT) and a system of hardware overlays for hardware configuration.

In order to enable MCP79410 first edit /boot/config.txt to enable i2c and load the i2c-rtc overlay:

dtparam=i2c_arm=on
dtoverlay=i2c-rtc,mcp7941x

Then, it is necessary to edit /lib/udev/hwclock-set and comment out the following lines:

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi

The file is run by udevd after the RTC has been initialized by the DT overlay. The responsible rule is in /lib/udev/rules.d/85-hwclock.rules.

Synchronize the time using ntpd (or use timedatectl) to set the correct time. Both ntp and timedatectl will update the hardware RTC after time change.

Leave a Reply

Your email address will not be published. Required fields are marked *