The Correct way to add a RTC
One of my Pis runs as a network server, providing DHCP and DNS services. To add more resilience to my home network I decided to get an I2C RTC module for it and add configure it to be the NTP server for my network (*).
I read several blogs and howtos about adding RTCs to PIs and nearly all of them get it wrong. They fudge some stuff into /etc/rc.local to set the system clock from the I2C RTC and don't remove the fake-hwclock or install a proper hwclock driver.
SO .... here's what to do. I've only tried this using a ds1307 based RTC module, but it should work (with appropriate changes) for RTCs based on other I2C clock chips.
Step 1: Follow the instructions on the Adafruit site https://learn.adafruit.com/adding-a-rea ... i?view=all to get your I2C RTC connected and tested, but DO NOT make the suggested changes to /etc/rc.local
Step 2:Make the changes to /etc/init.d/hwclock.sh as described here http://www.elevendroids.com/2012/12/set ... -raspbian/
Step 3: Ignore the first part of http://blog.remibergsma.com/2013/05/08/ ... pberry-pi/ but do follow the instructions on removing the fake-hwclock.
Your PI now has a proper RTC that can be used as a fall back by the NTP server incase the internet is unavailable, and which will also be kept accurate by being updated by the kernel.
PeterO
(*) Since I also run the DHCP server it was a simple matter to set that up to configure its clients to use my NTP server.
I read several blogs and howtos about adding RTCs to PIs and nearly all of them get it wrong. They fudge some stuff into /etc/rc.local to set the system clock from the I2C RTC and don't remove the fake-hwclock or install a proper hwclock driver.
SO .... here's what to do. I've only tried this using a ds1307 based RTC module, but it should work (with appropriate changes) for RTCs based on other I2C clock chips.
Step 1: Follow the instructions on the Adafruit site https://learn.adafruit.com/adding-a-rea ... i?view=all to get your I2C RTC connected and tested, but DO NOT make the suggested changes to /etc/rc.local
Step 2:Make the changes to /etc/init.d/hwclock.sh as described here http://www.elevendroids.com/2012/12/set ... -raspbian/
Step 3: Ignore the first part of http://blog.remibergsma.com/2013/05/08/ ... pberry-pi/ but do follow the instructions on removing the fake-hwclock.
Your PI now has a proper RTC that can be used as a fall back by the NTP server incase the internet is unavailable, and which will also be kept accurate by being updated by the kernel.
PeterO
(*) Since I also run the DHCP server it was a simple matter to set that up to configure its clients to use my NTP server.
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PICO,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Interests: C,Python,PICO,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Re: The Correct way to add a RTC
This last section on this page has worked for me on several RPis
http://wiki.sysadminblog.net/Rasbian
http://wiki.sysadminblog.net/Rasbian
Re: The Correct way to add a RTC
I wish I had found that earlierfruit-uk wrote:This last section on this page has worked for me on several RPis
http://wiki.sysadminblog.net/Rasbian

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PICO,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Interests: C,Python,PICO,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
-
- Posts: 663
- Joined: Wed Sep 25, 2013 8:43 am
- Location: Canterbury, Kent, UK
Re: The Correct way to add a RTC
Hi,
Really useful post thanks, I've consolidated into a list of instructions to save darting about all over the net....
----------------------
Enable the Kernel modules:-
Add the following:-
Save
Remove them from the blacklist by adding #
Make sure you see:-
Save & reboot
Install the i2c tools for testing:-
Run a test to see if all is well... for a rev 1 pi :
or for later, rev 2 Pi's :
You should see something like:-
load up the RTC module and test by running :
For older rev 1 pi's :
or for newer, rev 2 pi's :
Check the clock is running and can be read:-
Make sure pi is connected to internet so correct time is set....
Write the current system time to the hardware clock:-
Add the clock to the Kernel modules:-
Add:-
Save
Reconfigure the hwclock.sh script:-
After "unset TZ" at top add..
Find "case "$1" in" and edit as per:-
Save
Update the real HW Clock and remove the fake:-
Now that real hardware clock is installed, remove the fake package and it’s crons:-
Reboot
Really useful post thanks, I've consolidated into a list of instructions to save darting about all over the net....
----------------------
Enable the Kernel modules:-
Code: Select all
sudo nano /etc/modules
Code: Select all
i2c-bcm2708
i2c-dev
Remove them from the blacklist by adding #
Code: Select all
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Code: Select all
#blacklist spi-bcm2708
#blacklist i2c-bcm2708
Install the i2c tools for testing:-
Code: Select all
sudo apt-get install i2c-tools
Code: Select all
sudo i2cdetect -y 0
or for later, rev 2 Pi's :
Code: Select all
sudo i2cdetect -y 1
You should see something like:-
Code: Select all
pi@raspberrypi ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Code: Select all
sudo modprobe rtc-ds1307
Code: Select all
sudo bash
Code: Select all
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
exit
Code: Select all
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
exit
Code: Select all
sudo hwclock -r
Write the current system time to the hardware clock:-
Code: Select all
sudo hwclock -w
Code: Select all
sudo nano /etc/modules
Code: Select all
rtc-ds1307
Reconfigure the hwclock.sh script:-
Code: Select all
sudo nano /etc/init.d/hwclock.sh
Code: Select all
init_rtc_device()
{
[ -e /dev/rtc0 ] && return 0;
# load i2c and RTC kernel modules
modprobe i2c-dev
modprobe rtc-ds1307
# iterate over every i2c bus as we're supporting Raspberry Pi rev. 1 and 2
# (different I2C busses on GPIO header!)
for bus in $(ls -d /sys/bus/i2c/devices/i2c-*);
do
echo ds1307 0x68 >> $bus/new_device;
if [ -e /dev/rtc0 ];
then
log_action_msg "RTC found on bus `cat $bus/name`";
break; # RTC found, bail out of the loop
else
echo 0x68 >> $bus/delete_device
fi
done
}
Code: Select all
case "$1" in
start)
# If the admin deleted the hwclock config, create a blank
# template with the defaults.
if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
printf "0.0 0 0.0\n0\nUTC" > /etc/adjtime
fi
init_rtc_device
# Raspberry Pi doesn't have udev detectable RTC
#if [ -d /run/udev ] || [ -d /dev/.udev ]; then
#return 0
#fi
Update the real HW Clock and remove the fake:-
Code: Select all
sudo update-rc.d hwclock.sh enable
sudo update-rc.d fake-hwclock remove
Code: Select all
sudo apt-get remove fake-hwclock
sudo rm /etc/cron.hourly/fake-hwclock
sudo rm /etc/init.d/fake-hwclock
Re: The Correct way to add a RTC
Thanks for this great guide!
One additional (potential) issue: check /etc/default/hwclock and delete or comment out any lines with
It could save you a few hours of frustration
I (now) know raspbian-ua-netinst adds this line, but there could be other distros that do this too.
Gr.
Dirk.
One additional (potential) issue: check /etc/default/hwclock and delete or comment out any lines with
Code: Select all
HWCLOCKACCESS=no

I (now) know raspbian-ua-netinst adds this line, but there could be other distros that do this too.
Gr.
Dirk.
-
- Posts: 15
- Joined: Sat Apr 27, 2013 1:06 am
Re: The Correct way to add a RTC
Great help, itsmedoofer, but some clarification, please.
You wrote "load up the RTC module and test by running, i2c-0 for and old Pi:-"
Specifically how do you modify the command "sudo modprobe rtc-ds1307" if using an old Pi?
You wrote "load up the RTC module and test by running, i2c-0 for and old Pi:-"
Specifically how do you modify the command "sudo modprobe rtc-ds1307" if using an old Pi?
Re: The Correct way to add a RTC
It's the same command, the 'magic' has already been done here:purchasemail wrote:Specifically how do you modify the command "sudo modprobe rtc-ds1307" if using an old Pi?
Code: Select all
sudo bash
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
exit
Code: Select all
sudo bash
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
exit
Dirk.
Re: The Correct way to add a RTC
Hi,
according this step by step, my Raspi 's RTC DS3231 works.
But I found a problem: the time will delay after reboot.
I guess the reason is that when shutdown the system, the system will write date back to RTC, the process will cause the time delay about 1~2 sends.
according this step by step, my Raspi 's RTC DS3231 works.
But I found a problem: the time will delay after reboot.
I guess the reason is that when shutdown the system, the system will write date back to RTC, the process will cause the time delay about 1~2 sends.
Linux raspberrypi 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l GNU/Linux
RaspBerry Pi Model B+ | Sandisk Extreme microSDHC UHS-I 16GB Read:18.8M/s Write:18.2M/s | Sagem XG760N USB Dongle WiFi
RaspBerry Pi Model B+ | Sandisk Extreme microSDHC UHS-I 16GB Read:18.8M/s Write:18.2M/s | Sagem XG760N USB Dongle WiFi
-
- Posts: 663
- Joined: Wed Sep 25, 2013 8:43 am
- Location: Canterbury, Kent, UK
Re: The Correct way to add a RTC
Hi,
I dont think so, if I boot without the RTC attached my Pi boots with a date in the 1970's.
It sounds to me like the fake hardware clock may still be running OR that your RTC and internet time do not match...
Make sure pi is connected to internet so correct time is set....
Write the current system time to the hardware clock:-
sudo hwclock -w
Martin.
I dont think so, if I boot without the RTC attached my Pi boots with a date in the 1970's.
It sounds to me like the fake hardware clock may still be running OR that your RTC and internet time do not match...
Make sure pi is connected to internet so correct time is set....
Write the current system time to the hardware clock:-
sudo hwclock -w
Martin.
Last edited by itsmedoofer on Mon Dec 08, 2014 12:32 pm, edited 1 time in total.
-
- Posts: 663
- Joined: Wed Sep 25, 2013 8:43 am
- Location: Canterbury, Kent, UK
Re: The Correct way to add a RTC
Thanks Dirk, noticed several typos after reading back but I cannot edit nowDirkS wrote:.purchasemail wrote:Specifically how do you modify the command "sudo modprobe rtc-ds1307" if using an old Pi?

Re: The Correct way to add a RTC
Are you sure? AFAIK you should be able to edit your own posts. You should see an 'edit post' link or edit button (depending on the theme / style).itsmedoofer wrote:Thanks Dirk, noticed several typos after reading back but I cannot edit now
Gr.
Dirk.
Re: The Correct way to add a RTC
I've tided up a few bits in your post, see if I need to make any more, or I made any mistakes.itsmedoofer wrote:Thanks Dirk, noticed several typos after reading back but I cannot edit nowDirkS wrote:.purchasemail wrote:Specifically how do you modify the command "sudo modprobe rtc-ds1307" if using an old Pi?
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
-
- Posts: 663
- Joined: Wed Sep 25, 2013 8:43 am
- Location: Canterbury, Kent, UK
Re: The Correct way to add a RTC
Nice one thanks a lot texy appreciated !texy wrote:I've tided up a few bits in your post, see if I need to make any more, or I made any mistakes.
Texy
Re: The Correct way to add a RTC
Hi All,
Here is my updated Blog on Interfacing RaspberryPi with RTC, DS1307. Everything, from configuring and building the Kernel to enable RTC, DS1307 to Circuit diagram, to the Installation of I2C Tools like i2cdetect, i2cget, i2cset, et al. has been covered in detail. Apart, from changes to be done in etc.modules script, rc.local and config script to register the RTC-DS1307 to I2C Bus.
Here is my Blog Page:
http://blogsmayan.blogspot.in/p/adding.html
Thanks,
Rajiv.
Here is my updated Blog on Interfacing RaspberryPi with RTC, DS1307. Everything, from configuring and building the Kernel to enable RTC, DS1307 to Circuit diagram, to the Installation of I2C Tools like i2cdetect, i2cget, i2cset, et al. has been covered in detail. Apart, from changes to be done in etc.modules script, rc.local and config script to register the RTC-DS1307 to I2C Bus.
Here is my Blog Page:
http://blogsmayan.blogspot.in/p/adding.html
Thanks,
Rajiv.
-
- Posts: 663
- Joined: Wed Sep 25, 2013 8:43 am
- Location: Canterbury, Kent, UK
Re: The Correct way to add a RTC
Hi
a) The screen shots were Ubuntu, why not the Pi ?
b) With Raspbian you do not need to mess with the Kernel.
c) i2c-tools is available via apt-get, no need to download or compile.
d) There was no mention of this thread as a reference and the work PeterO done finding the correct info.....
Martin.
A couple of points,RBISWASX wrote:Here is my updated Blog on Interfacing RaspberryPi with RTC, DS1307.
a) The screen shots were Ubuntu, why not the Pi ?
b) With Raspbian you do not need to mess with the Kernel.
c) i2c-tools is available via apt-get, no need to download or compile.
d) There was no mention of this thread as a reference and the work PeterO done finding the correct info.....
Martin.
Re: The Correct way to add a RTC
Hi Martin,
I shall try to answer the queries to the best of my means:
a) The screen shots were Ubuntu, why not the Pi ?
Since, i was accessing my RaspberryPi via RS232toUSB Serial Adapter(PL203), connected via a MAX232 circuit to the Expansion header Tx, Rx, Vcc and Gnd, Pins P1-8, P1-10, P1-2 and P1-6, respectively. In this way, i was able to see the RaspberryPi Board shell instance via a Serial Program, Minicom, or Putty, by setting the port as ttyUSB0 and baudrate at 115200,8N1.
Please refer my first blog, in the first part " The Setup", of "Programming Interrupts in Raspberry Pi using a simple Kernel Character Device Driver", http://blogsmayan.blogspot.in/p/program ... ry-pi.html
b) With Raspbian you do not need to mess with the Kernel.
We need to modify the .config file, in order to enable the RTC-DS1307 module, which is otherwise set to 'm', manual.
After, that set tht config, and build new kernel image, and edit the /etc/modules to load the modules at runtime.
c) i2c-tools is available via apt-get, no need to download or compile.
If, one wants to try with different flavors of the latest linux Kernel, then it may or may not be present. better, we are able to
'configure' the package source, and then do 'make' and 'make install' to install the i2c-tools package.
d) There was no mention of this thread as a reference and the work PeterO done finding the correct info.....
Sorry, i shall add the references, from which all i have collated and compiled this work in total.
Regards,
Rajiv.
I shall try to answer the queries to the best of my means:
a) The screen shots were Ubuntu, why not the Pi ?
Since, i was accessing my RaspberryPi via RS232toUSB Serial Adapter(PL203), connected via a MAX232 circuit to the Expansion header Tx, Rx, Vcc and Gnd, Pins P1-8, P1-10, P1-2 and P1-6, respectively. In this way, i was able to see the RaspberryPi Board shell instance via a Serial Program, Minicom, or Putty, by setting the port as ttyUSB0 and baudrate at 115200,8N1.
Please refer my first blog, in the first part " The Setup", of "Programming Interrupts in Raspberry Pi using a simple Kernel Character Device Driver", http://blogsmayan.blogspot.in/p/program ... ry-pi.html
b) With Raspbian you do not need to mess with the Kernel.
We need to modify the .config file, in order to enable the RTC-DS1307 module, which is otherwise set to 'm', manual.
After, that set tht config, and build new kernel image, and edit the /etc/modules to load the modules at runtime.
c) i2c-tools is available via apt-get, no need to download or compile.
If, one wants to try with different flavors of the latest linux Kernel, then it may or may not be present. better, we are able to
'configure' the package source, and then do 'make' and 'make install' to install the i2c-tools package.
d) There was no mention of this thread as a reference and the work PeterO done finding the correct info.....
Sorry, i shall add the references, from which all i have collated and compiled this work in total.
Regards,
Rajiv.
Re: The Correct way to add a RTC
This is incorrect.RBISWASX wrote:b) With Raspbian you do not need to mess with the Kernel.
We need to modify the .config file, in order to enable the RTC-DS1307 module, which is otherwise set to 'm', manual.
After, that set tht config, and build new kernel image, and edit the /etc/modules to load the modules at runtime.
"m" means "module", not "manual". It means the driver has been built as a module and all you need to do is add it to /etc/modules.
If you change it to "y", then the driver will be built into the kernel, not as a module and adding it to /etc/modules is pointless.
So you don't need to mess with the kernel.
Re: The Correct way to add a RTC
Hi, people,
I made this procedure (edit file /boot/config.txt, but the best way to change it is by raspi-config > 8. Advanced options > A6. I2C), but i had a trouble and my rtc with chip pcf8563 conected to my Pi.
When I try to use the command to update time of rtc this error occours:
I also used the dmesg command to find any error. This is the message related of i2c and pcf8563:
The rtc module is loaded and detected, in according with i2cdetect command:
I don't know why rtc chip is not working. Is it necessary any configuration or the issue is with rtc chip (ex. low battery)?
I made this procedure (edit file /boot/config.txt, but the best way to change it is by raspi-config > 8. Advanced options > A6. I2C), but i had a trouble and my rtc with chip pcf8563 conected to my Pi.
When I try to use the command to update time of rtc this error occours:
Code: Select all
pi@raspberrypi ~ $ sudo hwclock -w
hwclock: select() to /dev/rtc0 to wait for clock tick timed out: Arquivo ou diretório não encontrado
Code: Select all
pi@raspberrypi ~ $ dmesg|grep i2c
[ 5.503791] bcm2708_i2c_init_pinmode(0,0)
[ 5.666925] bcm2708_i2c_init_pinmode(0,1)
[ 5.674016] bcm2708_i2c 20205000.i2c: BSC0 Controller at 0x20205000 (irq 79) (baudrate 100000)
[ 5.991503] bcm2708_i2c_init_pinmode(1,2)
[ 6.206989] bcm2708_i2c_init_pinmode(1,3)
[ 6.213990] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
[ 12.084975] i2c /dev entries driver
[ 39.789832] i2c i2c-1: new_device: Instantiated device pcf8563 at 0x51
Code: Select all
pi@raspberrypi ~ $ dmesg|grep rtc
[ 39.782178] rtc-pcf8563 1-0051: chip found, driver version 0.4.3
[ 39.789131] rtc (null): invalid alarm value: 2015-2-6 62:47:0
[ 39.789709] rtc-pcf8563 1-0051: rtc core: registered rtc-pcf8563 as rtc0
Code: Select all
pi@raspberrypi ~ $ 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
I don't know why rtc chip is not working. Is it necessary any configuration or the issue is with rtc chip (ex. low battery)?
Kazzttor
Diadema-SP, Brazil
Linux-Windows-Mac User
Raspberry Pi Lover
Diadema-SP, Brazil
Linux-Windows-Mac User
Raspberry Pi Lover
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: The Correct way to add a RTC
Please post the output from a uname -a command.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: The Correct way to add a RTC
Code: Select all
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.18.3+ #741 PREEMPT Fri Jan 23 13:32:52 GMT 2015 armv6l GNU/Linux
Kazzttor
Diadema-SP, Brazil
Linux-Windows-Mac User
Raspberry Pi Lover
Diadema-SP, Brazil
Linux-Windows-Mac User
Raspberry Pi Lover
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: The Correct way to add a RTC
Well done, you've shot yourself in the foot by running rpi-update when it wasn't needed.
Edit /boot/config.txt add then reboot.
Edit /boot/config.txt add
Code: Select all
device_tree_param=i2c1=on
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: The Correct way to add a RTC
"m" means "module", not "manual"rpdom wrote:This is incorrect.RBISWASX wrote:b) With Raspbian you do not need to mess with the Kernel.
We need to modify the .config file, in order to enable the RTC-DS1307 module, which is otherwise set to 'm', manual.
After, that set tht config, and build new kernel image, and edit the /etc/modules to load the modules at runtime.
"m" means "module", not "manual". It means the driver has been built as a module and all you need to do is add it to /etc/modules.
If you change it to "y", then the driver will be built into the kernel, not as a module and adding it to /etc/modules is pointless.
So you don't need to mess with the kernel.
Yes, i made a Typo mistake while typing. i failed to check it.
"If you change it to "y", then the driver will be built into the kernel, not as a module and adding it to /etc/modules is pointless.
So you don't need to mess with the kernel."
Incorrect. You will in that case need to do
# modprobe rtc-ds1307
That's why, one can add it in /etc/modules and the module is loaded, as the Kernel starts up,and one does not
need to load it, manually using #modprobe.
Thus, better, change the .config file and make it to "y", and add "rtc-ds1307" in /etc/modules, to ensure that the
Module would be loaded at Kernel initialization startup time.
Also, say, if One needed to implement the RTC Clock using DS-1302, or DS1331, clearly, one needs to look into
the Kernel Config file, and enable the Module, since not all of them are enabled by Default. My main, purpose was
to explain, where it needs to be done to do so. Thus, u do need to look into the Kernel a Bit. Mess is the wrong word
here, when all one, can do is to share and learn. Hope, u get my point.
Regards,
Rajiv.
Re: The Correct way to add a RTC
kazzttor wrote:Hi, people,
I made this procedure (edit file /boot/config.txt, but the best way to change it is by raspi-config > 8. Advanced options > A6. I2C), but i had a trouble and my rtc with chip pcf8563 conected to my Pi.
When I try to use the command to update time of rtc this error occours:
I also used the dmesg command to find any error. This is the message related of i2c and pcf8563:Code: Select all
pi@raspberrypi ~ $ sudo hwclock -w hwclock: select() to /dev/rtc0 to wait for clock tick timed out: Arquivo ou diretório não encontrado
Code: Select all
pi@raspberrypi ~ $ dmesg|grep i2c [ 5.503791] bcm2708_i2c_init_pinmode(0,0) [ 5.666925] bcm2708_i2c_init_pinmode(0,1) [ 5.674016] bcm2708_i2c 20205000.i2c: BSC0 Controller at 0x20205000 (irq 79) (baudrate 100000) [ 5.991503] bcm2708_i2c_init_pinmode(1,2) [ 6.206989] bcm2708_i2c_init_pinmode(1,3) [ 6.213990] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000) [ 12.084975] i2c /dev entries driver [ 39.789832] i2c i2c-1: new_device: Instantiated device pcf8563 at 0x51
The rtc module is loaded and detected, in according with i2cdetect command:Code: Select all
pi@raspberrypi ~ $ dmesg|grep rtc [ 39.782178] rtc-pcf8563 1-0051: chip found, driver version 0.4.3 [ 39.789131] rtc (null): invalid alarm value: 2015-2-6 62:47:0 [ 39.789709] rtc-pcf8563 1-0051: rtc core: registered rtc-pcf8563 as rtc0
Code: Select all
pi@raspberrypi ~ $ 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
I don't know why rtc chip is not working. Is it necessary any configuration or the issue is with rtc chip (ex. low battery)?
1>
In '/etc/rc.local '.
Add the following lines, at the beginning, of the file:
echo pcf8563 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
/sbin/hwclock -s
update-rc.d -f fake-hwclock remove
update-rc.d -f ntp remove
2 >
In the /etc/modules' file, which specifies the modules to be loaded at boot time,
ADD the rtc-pcf8563 Module, to be loaded during Kernel Initialization, after bootup:
# /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.
i2c-dev
i2c-bcm2708
rtc-pcf8563
snd-bcm2835
3>
After this, in the boottime parameters and bootargs of RaspberryPi, add the following argument:
rtc.i2c=pcf8563,1,0x68
In the file '/boot/cmdline.txt' in the Boot Partition,the above
lines would be added in the following way:
dwc_otg.lpm_enable=0 rtc.i2c=pcf8563,1,0x68 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1
root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
After, this power in the RTC pcf8563 circuit first using 3.3V battery, and after that
power up RaspberryPi.
Please, look into my Blog below for more detailed and elaborate Explanation:
http://blogsmayan.blogspot.in/p/adding.html
To Continue from ABOVE:
Next, we delete the current Timezone and update the Timezone using the below commands:
# rm -f /etc/localtime
# ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
After, this set the Time, using 'date' command:
# date --set="2014-11-23 18:35:47"
and, update the HWClock using:
/sbin/hwclock --systohc
Now, check, the date and time using 'date' command:
#date
After, Date and Time has been set correctly, restart RaspberryPi.
Now, check the date and time, after restarting RaspberryPi.
#date
Thus, HOPE, it clears yours queries and doubts...
Thanks,
Rajiv.
Last edited by RBISWASX on Thu Jan 29, 2015 4:03 pm, edited 2 times in total.
-
- Posts: 663
- Joined: Wed Sep 25, 2013 8:43 am
- Location: Canterbury, Kent, UK
Re: The Correct way to add a RTC
All I can say is I did not need to compile my own kernel to use my ds1307 based RTC module.
The procedure above was done with a stock kernel and stock distribution.
The procedure above was done with a stock kernel and stock distribution.
Re: The Correct way to add a RTC
I know that.itsmedoofer wrote:All I can say is I did not need to compile my own kernel to use my ds1307 based RTC module.
The procedure above was done with a stock kernel and stock distribution.
I wanted to do away with #modprobe for my Project, and had to load, as soon as the Board bringup happened.
Also, i had to check with DS1338, DS1302 and DS1307 RTC Chips. Thus, i had to enable these Modules in the
Kernel and build the Kernel.