Real Time Clock


The realtime clock is provided by an NXP PCF8563, which is supported directly by the Raspberry Pi Linux distribution for use as a hardware clock. This is battery backed by the on board LiPo cell. The RTC time can be set manually or automatically updated from an NTP server when this is available. When the Raspberry Pi is halted,  Ardh@t can access the RTC to in order to wake up the Raspberry Pi at a predetermined time.

The PCF8563 features, taken from the product datasheet, are:

  • Provides year, month, day, weekday, hours, minutes, and seconds based on a 32.768kHz quartz crystal
  • Century flag
  • Clock operating voltage: 1.0V to 5.5V at room temperature
  • Low backup current; typical 0.25uA at VDD = 3.0V and Tamb = 25°C
  • 400kHz two-wire I2C-bus interface (at VDD = 1.8V to 5.5V)
  • Programmable clock output for peripheral devices (32.768kHz, 1.024kHz, 32Hz, and 1Hz)
  • Alarm and timer functions

In order to use the PCF8563 as a hardware system clock for Raspberry Pi we need to make sure the kernel modules are loaded at boot time…

Edit /etc/modules to include pcf8563

~ $ sudo nano /etc/modules


# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-bcm2708
i2c-dev
rtc-pcf8563

…and that the hwclock is loaded at startup

Edit /etc/rc.local to end as shown...

~ $ sudo nano /etc/rc.local


modprobe i2c-bcm2708
echo pcf8563 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
modprobe rtc-pcf8563
hwclock -s

exit 0

Save, then reboot with sudo reboot

Now you can check the results, first with i2cdetect -y 1, which shows that the i2c driver loaded (and that in this case we have 3 i2c devices present)

Then with sudo hwclock --rtc /dev/rtc0 -r --debug