# How to setup a MCP79410 real time clock?

I was trying to set up a MCP79410 real time clock (RTC) and had to search quite a bit until I found a way to integrate the RTC's time signal into my Raspbian Jessie:

Apparently, even there, some things changed over the last updates of Raspbian and there does not seem to be a huge crowd using this particular chip (as opposed to, e.g. the DS1307).

I specifically wanted to connect a MCP79410 already hooked up to an ABS07 quartz crystal and a HU2032-LF battery to my Raspbbery Pi Model 3B running Raspbian Jessie 4.4.38-V7+ #938. The implementation should be as easy as possible and simply provide me with a correct system time even if the RPi is disconnected from the internet.

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
``````

I see these instructions and the lack of seeing your wiring nor the output of your i2cdetect query. This means that you have the correct instructions to make it work. Answer: Simply follow them.

Let me point out that this clock is to be set by the Pi in the first place. That implies that the Pi is connected to the Internet and gets a NTP-based time and date setting periodically.

Then you must do extra work to keep this clock synchronized to the Pi.

So I don't see any use-case for using this module in the first place.

My suggestion is that you just let the Pi keep its own time.

• Well, yes, myinstructions work - that's why I put them here. To make it easier for others ;-) – Fantilein1990 May 19 '17 at 15:38
• Regarding the purpose of the clock: My Pi had a very unreliable internet connection. It was rebooted every now and then and I needed it to keep the time very accurately, even if it didn't have an internet connection upon reboot. In this case, a Pi can run into trouble keeping the time, so I added a RTC and a small battery feeding the RTC. Problem solved. Is this an acceptable use-case? :-) – Fantilein1990 May 19 '17 at 15:43