In order to set up a MCP79410 real time clock (RTC, see manual), one needs to start by connecting it to one's RPi and a quartz crystal. The following is supposed to be a rough sketch on how to connect the pins to point one in the right direction - in practice, one might need capacitors to smooth signals or resitors to pull-up the SCL- and SDA-interface, depending for example on the battery and quartz crystal used.
X1: Connect to external 32.768 kHz quartz crystal
X2: Connect to external 32.768 kHz quartz crystal
VBAT: Connect to external battery
VSS: Connect to GND (e.g. RPi-Pin 9)
VCC: Connect to RPi-Pin 1 (3.3V)
MFP: -
SCL: Connect to RPi-Pin 5 (GPIO3_SCL1)
SDA: Connect to RPi-Pin 3 (GPIO3_SDA1)
After connecting the hardware components, one needs to set up a communication inferace between the MCP79410 and the RPi via I2C (can be activated via sudo raspi-config and therein "7 Advanced Options" -> "A7 I2C" -> "Yes" ). To do so, one should check their availability first:
i2cdetect -y 1
or, for older RPis, i2cdetect -y 0
should return
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f
70: -- -- -- -- -- -- -- --
This means: At 0x57 and 0x6f, the MCP79410 is listening for I2C communication. 0x57 leads to the EEPROM, a status register and a unique ID register whereas 0x6f is the address that leads to the RTC itself.
In order to establish a connection, the line rtc-mcp7941x
should be added to /etc/modules
and the line dtoverlay=i2c-rtc,mcp7941x
to /boot/config.txt
.
After a reboot, the i2cdetect
-command from above should return
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU
70: -- -- -- -- -- -- -- --
In order to use the newly established connection to provide one's RPi with a time signal, one needs to comment out the lines
if [ -e /run/systemd/system ] ; then
exit 0
fi
from /lib/udev/hwclock-set
.
Before the next step, one should make sure, one's system time is accurate (e.g. by comparing it to a radio controlled clock nearby).
Now, one sends one's current system time to the RTC using the command
hwclock -w
From now on, the RTC will keep the time and resynchronize the RPi's system time automatically on startup or manually by entering
hwclock -r