I have found several useful posts on the issues I'm seeing but nothing that gives a convincing solution. To make it really easy to reproduce I have created a shell script (below) that performs my entire configuration. Following a clean install of the March release of Rasbian Jessie, I run raspi-config and expand the disk image, copy on the script below, run the script as root, reboot.sudo hwclock -r
hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
Code: Select all
#!/bin/bash
# UniPi RTC driver setup
if [ "$EUID" -ne 0 ]
then echo "This script must be run as root"
exit
fi
echo Backup files
cp /boot/config.txt /boot/config.txt.bak
echo Enabling I2C bus...
if ! grep -q '^dtparam=i2c_arm=on' /boot/config.txt
then echo 'dtparam=i2c_arm=on' >> /boot/config.txt
fi
if ! grep -q '^dtparam=i2c_baudrate=400000' /boot/config.txt
then echo 'dtparam=i2c_baudrate=400000' >> /boot/config.txt
fi
echo Enabling the RTC chip...
if ! grep -q '^dtoverlay=i2c-rtc,mcp7941x' /boot/config.txt
then echo 'dtoverlay=i2c-rtc,mcp7941x' >> /boot/config.txt
fi
echo Getting i2c development tools
apt-get install -y i2c-tools
if ! grep -q '^i2c-dev' /etc/modules
then echo 'i2c-dev' >> /etc/modules
fi
echo Removing fake-hwclock...
apt-get purge -y fake-hwclock
update-rc.d -f fake-hwclock remove
apt-get autoremove -y
echo ' '
echo 'CODESYS for UniPi installed.'
echo ' '
echo '!!! REBOOT IS REQUIRED !!!'
echo ' '
read -p "Is it OK to reboot now? [y/N] " -n 1 -r
echo ' '
if [[ $REPLY =~ ^[Yy]$ ]]
then
reboot
else
echo 'Reboot to finish configuring drivers'
fi
echo ' '
NOTE: The hw clock can be seen to be functional - before rebooting I can write and check the clock like this
Any help is really appreciated. My target is to have all required setup in a single script.sudo hwclock -w
sudo hwclock --debug
hwclock from util-linux 2.25.2
Using the /dev interface to the clock.
Last drift adjustment done at 1460323428 seconds after 1969
Last calibration done at 1460323428 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
/dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change
...got clock tick
Time read from Hardware Clock: 2016/04/10 21:23:59
Hw clock time : 2016/04/10 21:23:59 = 1460323439 seconds since 1969
Sun 10 Apr 2016 21:23:59 UTC -0.724333 seconds