Really useful post -- it's helped me a lot setting up a hardware clock based on
bq32000. This chip can use a capacitor or a standard battery as backup supply. If you choose battery backup, you can set it up as a DS1307 by following instructions posted earlier on this thread.
If, like me, you go for a capacitor backup, you'll want to use the bq32k driver which supports trickle charging. Options are passed to the driver via the device tree and it took some trial an error to get everything right. I'm posting the detailed instructions here in case someone else wants to experiment with this chip.
Step 1: Enable i2c and install i2c tools as documented earlier on this thread. Check that your rtc is detected:
Code: Select all
pi@raspi ~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
If at this point you get UU instead of 68, there’s a driver using the rtc. Check the output of lsmod -- you don’t need to load any rtc driver via /etc/modules.
Step 2: We’ll now create an overlay with support for bq32000 and we need a device tree compiler for that:
Code: Select all
pi@raspi ~ $ sudo apt-get install device-tree-compiler
Create a .dts file from i2c-rtc-overlay.dtb in /boot/overlays. Give the output file a new name to reflect support for bq32000:
Code: Select all
pi@raspi ~ $ sudo dtc -I dtb -O dts -o /tmp/i2c-rtc-bq32k-overlay.dts /boot/overlays/i2c-rtc-overlay.dtb
Now it's time to edit the .dts file. Follow the existing tree structure and paste this entry:
Code: Select all
bq32000@68 {
compatible = "ti,bq32000";
trickle-resistor-ohms = <1120>;
reg = <0x68>;
};
For syntax and more available options check out
this link.
The configuration above enables trickle charging.
DO NOT enable trickle charging if using battery backup!
Next, convert the .dts file to .dtb:
Code: Select all
pi@raspi ~ $ sudo dtc -I dts -O dtb -o /boot/overlays/i2c-rtc-bq32k-overlay.dtb /tmp/i2c-rtc-bq32k-overlay.dts
Step 3: Get rid of fake-hwclock.
Code: Select all
pi@raspi ~ $ sudo apt-get remove fake-hwclock
pi@raspi ~ $ sudo update-rc.d -f fake-hwclock remove
pi@raspi ~ $ sudo rm /etc/fake-hwclock.data
Unplug the network cable and reboot. The system date will go back to Jan 1st 1970 00:00:00.
Step 4: Add "dtoverlay=i2c-rtc-bq32k,bq32000” to /boot/config.txt. Reboot and check that your rtc is accessible via hwclock.
Your system is now ready to get its time from the hardware clock. However, the rtc gets updated in the early stages of booting so it’ll end up on Jan 1st 1970 even when the Pi is connected to the internet and can get its time via ntp. A small change in hwclock-set will fix this:
Code: Select all
pi@raspi ~ $ sudo nano /lib/udev/hwclock-set
Comment the following three lines near the top of the script:
Code: Select all
#if [ -e /run/systemd/system ] ; then
# exit 0
#fi
Update the hwclock manually:
Unplug the network cable and reboot. The time should now be correct on both the Pi and hwclock.
This is it. No need to use the hwclock.sh as mentioned earlier on this thread. In fact, on my system it just doesn't run, even when enabled in rc.d. I'm using the latest release of raspbian:
Code: Select all
pi@raspi ~ $ uname -a
Linux raspi 4.1.12+ #825 PREEMPT Fri Nov 6 17:53:21 GMT 2015 armv6l GNU/Linux