= RTC based on the PCF8523 add-on board.

== introduction

image:./pic/pcf8523_1.jpg[]
image:./pic/pcf8523_2.jpg[]

== installation

 vi /boot/config.txt

----
///
dtoverlay=i2c-rtc,pcf8523
----

 vi /etc/modules-load.d/rtc.conf

----
i2c-bcm2708
i2c-dev
rtc-pcf8523
----

 reboot

== testing

 yum install i2c-tools
 
 i2cdetect -y 1

----
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
----

TIP: if 'UU' -> '68', check kernel module rtc_pcf8523

 cat /proc/driver/rtc

----
24hr		: yes
----

== configuration

 ntpdate ntp.belnet.be
 date -s "$(date '+%Y%m%d %T')"

 cat /proc/driver/rtc

----
rtc_time	: 17:16:20
rtc_date	: 2017-03-16
24hr		: yes
----

 hwclock -s

== debugging

 i2cdetect -l

----
i2c-1	i2c       	bcm2835 (i2c@7e804000)          	I2C adapter
----

 cat /etc/adjtime
 
 hwclock -r
 hwclock -w

 i2cdump -y -f -r 0-6 1 0x68 c
 
----
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 80 00 08 53 14 14 23                               ?.?S??#         
----

The command i2cdump -y -f -r 0-6 1 0x68 c can be used to dump the first 7 registers 
of the ds1307 which contain the time 

(the '-f' is needed only if you have the rtc driver installed; it overrides the reservation).

== references

https://www.kiwi-electronics.nl/adafruit-pirtc-pcf8523-real-time-clock-for-raspberry-pi

https://spellfoundry.com/docs/setting-up-the-real-time-clock-on-raspbian-jessie-or-stretch/

https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-up-and-test-i2c

https://cdn-learn.adafruit.com/downloads/pdf/adding-a-real-time-clock-to-raspberry-pi.pdf

