I've gone through a plethora of sources and found it a little confusing with too much information hence posting this question.

Firstly, the scenario is, I've set up my PI-3B(jessie) with PCF8523t RTC. The PI will get connected to the internet very occasionally. So, therefore there are two questions I would like to get the answer for:

  1. I need to know if the modifications done below are correct (please suggest which are the required/redundant steps)
  2. What is best way to synchronise the Network time to the RTC whenever the internet comes up?
  3. [NEW] Is it required to disable the NTP service?

The problem was if the PI(when not connected to internet) was showing the correct time if booted after 10 minutes, but if booted after a day, there was incorrect time shown.

Below is the software version of the PI

pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION="8 (jessie)"

The following changes were made

  1. In the /boot/config.txt file

uncommented the 'dtparam=i2c_arm=on' and added 'dtoverlay=i2c-rtc,pcf8523'

  1. The following commands were run
apt-get -y remove fake-hwclock
rm /etc/cron.hourly/fake-hwclock
update-rc.d -f fake-hwclock remove
rm /etc/init.d/fake-hwclock
systemctl disable fake-hwclock
  1. Commented out the following lines in /lib/udev/hwclock-set
#if [ -e /run/systemd/system ] ; then
# exit 0
#/sbin/hwclock --rtc=$dev --systz --badyear
#/sbin/hwclock --rtc=$dev --systz
  1. Updated the (correct) system time into the hardware clock by
hwclock -w
  1. Added the below modules to the /etc/modules file
  1. Edited the /etc/rc.local with the following lines

Ensured there is '#!/bin/bash' at the beginning of the script

sleep 2
pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
( sleep 2; hwclock -s ) &
  1. Edited the /etc/default/hwclock with
  1. Added the below as root's cronjob(done to sync the network time to RTC)
    */5 * * * *   ntpdate 0.pool.ntp.org || ( hwclock --adjust; hwclock -s )
  • 2
    Why are you still using Raspbian Jessie? Your need to switch to Raspbian Stretch.
    – CoderMike
    Jun 11, 2019 at 21:20
  • I am not too sure if you should do the following: "uncommented the 'dtparam=i2c_arm=on' and added 'dtoverlay=i2c-rtc,pcf8523'" You are disabling I2C and might cause a problem to other I2C devices. I confess I have not studies your procedure too carefully.
    – tlfong01
    Jun 12, 2019 at 2:09

2 Answers 2


The ONLY thing you have to do is include in /boot/config.txt:


DO NOT fiddle with the software or attempt to manually synchronise - it all happens AUTOMATICALLY.

See https://raspberrypi.stackexchange.com/a/51782/8697

If you need to set the RTC initially (if NTP not available) you can use hwclock --set see man hwclock for details.

  • As per your suggestion removed everything, the only changes done are sleep 2 && hwclock -s in /etc/rc.local file and uncommented HWCLOCKACCESS=yes and HCTOSYS_DEVICE=rtc0 in /etc/default/hwclock, and still I'm facing the same issue
    – Manoj
    Jun 26, 2019 at 6:24
  • @Manoj How is this following my suggestion "DO NOT fiddle with the software or attempt to manually synchronise"?
    – Milliways
    Jun 26, 2019 at 6:57
  • Yeah I tried removing the command from rc.local and that too failed. Keeping that command in rc.local had a much better success rate so I retained it
    – Manoj
    Jun 26, 2019 at 8:05


  1. How to sync Network time to the RTC?

  2. How to use PCF8523RTC dtoverlay=i2c-rtc,pcf8523RTC


  1. After booting, you can use the following python statements to sync Network Time, then update PCF8523.

python to update time

  1. The best reference I can find about linux hwclock is the one listed in the reference below. It describes how linux, on booting, sets system clock from hardware clock. You need to make clear the hardware clock, system clock, and even Section 9.1 fake-hw_clock.

  2. I would suggest to update from Jessie to stretch, for two reasons: (1) What you read from archLinux about hwclock might be applicable to jessie, but not stretch. (2) Many drivers work in jessie might not work for stretch, because the driver author retires and no longer support os upgrades. That is why I always avoid DTO (dtoverlay) and rely on python. I wrote my little simple python driver for RTC DS3231 and found my effort is worth it. I have not used PCF8523. Perhaps I should later take a look an update my answer here.


PCF8523 Datasheet - NXP

Adafruit PCF8523 Real Time Clock

DS3231 vs DS3231 Benchmarks

RTC comparison - 2017feb03

WaveShare's DS3231 RTC Module 6 Step Setup Guide

DS3231 RTC Simple Setup Functions

How do I fix incorrect timestamps in my bash script that launches on startup?

hwclock (Time) - archLinux

In an operating system, the time (clock) is determined by four parts:

time value, time standard, time zone, and Daylight Saving Time (DST) if applicable.

This article explains what they are and how to read/set them.

Two clocks are present on systems:

a hardware clock and

a system clock which are also detailed in this article.

Standard behavior of most operating systems is:

Set the system clock from the hardware clock on boot.

Keep accurate time of the system clock...

Set the hardware clock from the system clock on shutdown.


1 Hardware clock

1.1 Read hardware clock

1.2 Set hardware clock from system clock

2 System clock

2.1 Read clock

2.2 Set system clock

3 Time standard

3.1 UTC in Windows

3.2 UTC in Ubuntu

4 Time zone

5 Time skew

6 Time synchronization

7 Per-user/session or temporary settings

8 Troubleshooting

8.1 Clock shows a value that is neither UTC nor local time

9 Tips and tricks

9.1 fake-hwclock

10 See also, ...

Update 2019jun12hkt1050

I googled comparisons of DS3231 with PCF8523 and my quick conclusion is that they are both good for hobbyists projects. DS3231 modules has the advantage that there is a temperature sensor built into the chip and an EEPROM built into the module. So I would prefer DS3231.

ds3231 vs pcf8523

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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