2

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

  • Can you paste the configuration files in your answer, please? – Jacobm001 Feb 9 '16 at 0:30
  • 1
    The link you quoted is old, and relates to a previous OS. Tell us WHAT YOU HAVE DONE. We can only guess otherwise. – Milliways Feb 9 '16 at 1:02
  • I have added the config files, let me know if you need anything else. – Clémentine Feb 9 '16 at 13:56
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
  • It's funny you mention the driver is not the same, I hadn't noticed. In their tutorial they talk about ds1307 only. thepihut.com/blogs/raspberry-pi-tutorials/… – 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 0: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
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.

  • it seems it has solved my problem! – Clémentine Feb 9 '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 9 '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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.