# Setting the Real Time Clock hardware

## Check the precence of RTC chip

	$ sudo apt update
	$ sudo apt install python-smbus i2c-tools

Enable the I2C port using raspi-config:

	$ sudo raspi-config

Get the list of I2C ports available:	
	
	$ sudo i2cdetect -l

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


Check the presence of RTC chip on i2c-1 bus by typing:

	$ sudo i2cdetect -y 1

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

68 is the hex address of the real time clock chip.

## Use the hardware RTC instead of sofware fake-hwclock 

The fake-hwclock is a utility used on systems without an RTC to save the time at regular intervals and when the system is shutting down.
<br/>
To disable this fuction type these commands:

	$ sudo apt -y remove fake-hwclock
	$ sudo update-rc.d -f fake-hwclock remove
	$ sudo systemctl disable fake-hwclock

Edit file <code>/lib/udev/hwclock-set</code>:

	$ sudo nano /lib/udev/hwclock-set


and comment the lines:

	#!/bin/sh
	# Reset the System Clock to UTC if the hardware clock from which it
	# was copied by the kernel was in localtime.
	
	dev=$1
	
	#if [ -e /run/systemd/system ] ; then
	# exit 0
	#fi

Edit the file <code>/etc/modules</code>:

	$ sudo nano /etc/modules

and add these contents:

	# /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.
	
	i2c-dev
	rtc-8523

Edit file <code>/etc/rc.local</code>:

	$ sudo nano /etc/rc.local 
	
and insert these lines before the <code>exit 0</code>:

	# PCF8523
	echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
	
Reboot: 

	$ sudo reboot

Re-type the command:

	$ sudo i2cdetect -y 1

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

Address 0x68 is Real Time Clock

@include='adv_cmpanel' 
