3

I have been trying to install a RTC on my raspberry pi 2 (running Raspbian Jessie lite 2015-11-21) and I run into the following problem that puzzles me:

  1. I set the correct time on the hardware clock and shut down the pi.
  2. I unplug the ethernet cable so that the pi is off the internet.
  3. I turn on again after about 7/8 minutes and check date and hwclock -r: and here is what I get:

    • Date gives me the correct time (and so does /var/log/syslog). --> so the RTC has done its job.
    • But hwclock -r gives me the wrong time! So it seems hwclock is overwritten by something at boot, after it has passed the time correctly to the system.

And of course if I reboot a second time, then date becomes wrong.

Screen shot

Anyone has an idea of how to fix this?

Here are the current config files. I started without changing config.txt and hwclock-set, and the result was the same:

sudo nano /boot/config.txt: added at the end:

dtoverlay=i2c-rtc

/lib/udev/hwclock-set: commented out:

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

/etc/modules

i2c-bcm2708
i2c-dev
rtc-ds1307

and /etc/rc.local

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s

The RTC model: http://thepihut.com/products/mini-rtc-module-for-raspberry-pi?variant=758601217

Clémentine
  • 353
  • 2
  • 4
  • 14

2 Answers2

3

The only thing you should need to do is to add the following line to /boot/config.txt

dtoverlay=i2c-rtc,ds3231 

Inserting commands into init.d or attempting to load modules is unecessary (and may interfere with normal operation). Device Tree should do all this automatically.

You can use ds1307 if you actually have one (the device you linked uses DS3231)

You can turn off fake-hwclock if you want, but it should not be necessary. If you do want to do this you should use the systemd command

systemctl stop fake-hwclock.service
Milliways
  • 59,890
  • 31
  • 101
  • 209
  • It's funny you mention the driver is not the same, I hadn't noticed. In their tutorial they talk about ds1307 only. http://thepihut.com/blogs/raspberry-pi-tutorials/17209332-adding-a-real-time-clock-to-your-raspberry-pi – Clémentine Feb 10 '16 at 14:13
  • I tried what you said, removing all the RTC config form /etc/ and adding ds3231 after dtoverlay=i2c-rtc and it works fine. Hopefully this is the end of the story.. – Clémentine Feb 10 '16 at 14:44
  • one question though, in Dmesg, I get the line: [ 4.936860] rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0 with do I get rtc-ds1307 there? – Clémentine Feb 10 '16 at 14:45
  • I also get the message rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0. I don't know what it means. The ds1307 and ds3231 are very similar chips (at least the internal registers which hold time) so I suspect they are sharing a common driver. – Milliways Feb 11 '16 at 00:47
  • I left my pi to sleep for about half a day and when I plugged it again, the time got reset to 1 jan 1970. Dmesg: rtc-ds1307 1-0068: SET TIME! rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0 Do you think it's a pb with the clock this time? – Clémentine Feb 11 '16 at 13:21
  • it seems it's a problem with the RTC super-capacitor running out of charge this time. – Clémentine Feb 11 '16 at 14:18
  • @Clémentine The module I use has a Lithium battery. If fake-hwclock is running it (hopefully) will set time to last used until NTP takes over. I have only tested with RTC disconnected. – Milliways Feb 11 '16 at 22:47
  • As of 2017-04-10-raspbian-jessie, this no longer works. The RTC can be accessed with the hwclock command, but it seems not to be used by systemd. Could you please update your answer? – Edgar Bonet May 12 '17 at 15:32
1
sudo update-rc.d fake-hwclock disable S 6

...And reboot. See man fake-hwclock. This is enabled by default on current versions of Raspbian.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
  • it seems it has solved my problem! – Clémentine Feb 09 '16 at 19:05
  • @Clémentine It made your problem go away. You should set the correct overlay in /boot/config.txt and not modify /etc/rc.local. You are mixing 2 different incompatible methods. My setup (with fake-hwclock) works properly (even if the RTC is missing). The device you linked uses DS3231 so you are not using the correct driver. – Milliways Feb 09 '16 at 22:38
  • It turns out it hasn't solved my problem fully in fact.. From time to time (and i'm not sure yet when..) the hwclock is reset at boot to 1 jan 1970. I will investigate further and post an update. – Clémentine Feb 10 '16 at 14:14
  • Tried this, and found my Raspberry in 1970. – Edgar Bonet May 12 '17 at 15:41