dislick
Posts: 10
Joined: Mon Oct 24, 2016 9:35 am

RTC (DS3231) jumps to 2016-11-03 after reboot

Tue May 01, 2018 6:35 am

Hello Forum

We are using the DS3231 RTC to keep the time on our CM3 after a shutdown. Everything worked flawlessly a couple of weeks ago, however today I ran into weird behaviour. After a reboot, longer shutdown and even after taking the battery out for a couple minutes the RTC jumps to 2016-11-03 17:17:??. I can set it to the proper time but after a reboot it resets again:

Code: Select all

pi@raspberrypi:~ $ timedatectl
      Local time: Tue 2018-05-01 08:17:17 CEST
  Universal time: Tue 2018-05-01 06:17:17 UTC
        RTC time: Thu 2016-11-03 17:17:15
       Time zone: Europe/Zurich (CEST, +0200)
 Network time on: no
NTP synchronized: yes
 RTC in local TZ: no
pi@raspberrypi:~ $ sudo hwclock -w
pi@raspberrypi:~ $ sudo hwclock -r
2018-05-01 08:17:25.978832+0200
We are using the following device tree overlays:

Code: Select all

dtoverlay=spi-gpio35-39
dtoverlay=i2c1-bcm2708,sda1_pin=44,scl1_pin=45,pin_func=6
dtoverlay=i2c-rtc,ds3231
Changing the battery didn't help, I tried five different ones.

What could I try to resolve this? Any ideas?


More information that may be relevant:

Code: Select all

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l GNU/Linux

Code: Select all

pi@raspberrypi:~ $ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 SHM(18)         .DCF.            0 l    -   64    0    0.000    0.000   0.000
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 1.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 2.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 3.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 ntp1.as34288.ne .STEP.          16 u    -   64    0    0.000    0.000   0.000
 magma.woody.ch  .STEP.          16 u    -   64    0    0.000    0.000   0.000
 bwntp1.bluewin. .STEP.          16 u    -   64    0    0.000    0.000   0.000
 time.sunrise.ne .STEP.          16 u    -   64    0    0.000    0.000   0.000
+212.25.15.129 ( 131.188.3.222    2 u   46   64    1   12.940   -0.257   1.086
*zh.danzuck.ch   162.23.41.55     2 u   21   64    1    9.476   -0.584   1.024
+212.25.15.128 ( 131.188.3.222    2 u   19   64    1   10.636   -1.222   0.982

dislick
Posts: 10
Joined: Mon Oct 24, 2016 9:35 am

Re: RTC (DS3231) jumps to 2016-11-03 after reboot

Tue May 01, 2018 7:05 am

Update!

I used a brand new CM3 and flashed 2018-04-18-raspbian-stretch-lite.img onto it. Then I setup the RTC by enabling I2C using raspi-config and adding the appropriate dtoverlays in /boot/config.txt. Everything works as expected!

Then I removed fake-hwclock and disabled systemd-timesyncd.service and rebooted. Now it looks like this:

Code: Select all

pi@raspberrypi:~ $ timedatectl
      Local time: Thu 2016-11-03 17:17:01 UTC
  Universal time: Thu 2016-11-03 17:17:01 UTC
        RTC time: Tue 2018-05-01 07:00:22
       Time zone: Etc/UTC (UTC, +0000)
 Network time on: no
NTP synchronized: no
 RTC in local TZ: no
The RTC works (which is great), but I am confused about the local time. It is set to 2016-11-03 instead of the expected 1970-01-01. Why would that be?

dislick
Posts: 10
Joined: Mon Oct 24, 2016 9:35 am

Re: RTC (DS3231) jumps to 2016-11-03 after reboot

Tue May 01, 2018 7:56 am

Update 2!

Okay, after installing NTP my original problem appeared again:

Code: Select all

pi@raspberrypi:~ $ timedatectl
      Local time: Thu 2016-11-03 17:17:08 UTC
  Universal time: Thu 2016-11-03 17:17:08 UTC
        RTC time: Tue 2018-05-01 07:52:48
       Time zone: Etc/UTC (UTC, +0000)
 Network time on: no
NTP synchronized: no
 RTC in local TZ: no
 
pi@raspberrypi:~ $ sudo /etc/init.d/ntp start
[ ok ] Starting ntp (via systemctl): ntp.service.

pi@raspberrypi:~ $ timedatectl
      Local time: Thu 2016-11-03 17:17:24 UTC
  Universal time: Thu 2016-11-03 17:17:24 UTC
        RTC time: Thu 2016-11-03 17:17:24
       Time zone: Etc/UTC (UTC, +0000)
 Network time on: no
NTP synchronized: yes
 RTC in local TZ: no
NTP seems to set the hardware clock to the system time when launching, even though the system time is wrong. How can I make sure that the system time is set to the RTC time before NTP launches?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1731
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RTC (DS3231) jumps to 2016-11-03 after reboot

Tue May 01, 2018 8:58 am

There's an up-to-date tutorial here: https://pimylifeup.com/raspberry-pi-rtc/ You'll need to follow from step 5.

dislick
Posts: 10
Joined: Mon Oct 24, 2016 9:35 am

Re: RTC (DS3231) jumps to 2016-11-03 after reboot

Tue May 01, 2018 9:08 am

Thank you Phil, that's what I was looking for. I am going to add the solution here in this thread, in case your link goes down one day:

Now that we have disabled the fake-hwclock package we can proceed with getting the original hardware clock script that is included in Raspbian up and running again by commenting out a section of code.

Run the following command to begin editing the original RTC script.

sudo nano /lib/udev/hwclock-set

7. Find and comment out the following three lines by placing # in front of it as we have done below.

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

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 3 guests