Receive email notifications for:
Was this page helpful?

A Battery-backed Real Time Clock
A Battery-backed Real Time ClockEdit

From $1

    The Beaglebone does not have a persistent clock, so when it is power-cycled, its clock must be set from an external source.  Normally, SensorGnomes use a GPS for this purpose, but in some deployments, (e.g. inside a metal-clad structure) this isn't feasible.  For this purpose, a small Real Time Clock (RTC) evaluation board can be used to provided timekeeping when a SensorGnome is reset or powered down.

    As of mid 2014, the SG software will automatically detect and use such a clock to initialize the system clock at boot time.

    Hardware
    Edit section

    We chose the Gravitech I2C-RTC board (available here), which provides a battery-powered RTC based on the Maxim DS1340-33 RTC chip.  There are drivers for this and many other RTC chips in the standard Linux kernel distribution.  A 3V lithium battery must be installed in the I2C-RTC board if you want it to keep time when the beaglebone is off.

    Connection
    Edit section

    The I2C-RTC is connected directly to the beaglebone's P9 expansion header using short lengths of 22 gauge wire as so:
    Battery Backed Clock 1.JPG

     

     

    I2C-RTC       Beaglebone
     Pin           P9 Pin #
    
    VCC (+3.3V)       3
    GND               1
    SCL (clock)      19
    SDA (data)       20
    




    We soldered header pins into the holes on the I2C-RTC.  On that end of the hook-up wires, we crimped and soldered header plug contacts.  At the Beaglebone end of the hook-up wires, we soldered a male DB9-style pin to the other end of the wire.  The latter can be lodged gently but firmly into the appropriate P9 header pin-slots.  For use in the field, we will solder one end of wire directly into the I2C-RTC board, then use DB9-style male pins on the other end, but with heat-shrink tubing covering any metal surface emerging from the board or header block at the ends.  The I2C-RTC board will be attached to the lid of the acrylic case.

    When correctly wired, the board's LED will be lit when the I2C-RTC is operating from Beaglebone power. However, there is a solder-trace which can be removed to disable this for low-power field deployments.

    Detecting and Enabling the Device
    Edit section

    If you install the i2ctools package on your SensorGnome, and then open a shell window, you can detect the I2C-RTC using the i2cdetect command:

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

    The UU in row 60, column 8 indicates a device was detected at address 0x68, which is correct for ds1307-compatible devices such as this one.  To use the I2C-RTC, issue the following command:

    # echo ds1307 0x68 > /sys/class/i2c-dev/i2c-3/device/new_device 
    

    which will generate these lines in your system log, visible via dmesg | tail

    [  125.921337] i2c i2c-3: new_device: Instantiated device ds1307 at 0x68
    [  125.944866] rtc-ds1307 3-0068: rtc core: registered ds1307 as rtc1
    [  125.951495] rtc-ds1307 3-0068: 56 bytes nvram
    

    Note: the i2ctools package is not required in order to use the device, but is helpful for debugging connection problems.

    Getting and Setting the RTC date/time
    Edit section

    The device name highlighted above (rtc1) indicates where in /dev the device is to be found.  You can see its date/time using hwclock, as so:

    # hwclock --show -u -f /dev/rtc1         ## show the i2c-rtc's date/time in UTC
    Tue May 14 17:34:38 2013  0.000000 seconds
    

    You can copy the current system clock (presumably already correctly set via ntpdate, GPS, or by hand) to the I2C-RTC by doing:

    # hwclock --systohc -u -f /dev/rtc1      ## set the i2c-rtc clock from the system date/time
    

    And conversely, you can set the system clock from the I2C-RTC by doing:

    # hwclock --hctosys -u -f /dev/rtc1      ## set the system date/time from the i2c-rtc
    

    If your kernel generated a device name other than rtc1, you must use that one instead.

    Accuracy
    Edit section

    In an over-the-weekend lab test, we found the I2C-RTC drift to be on the order of 1 second per day relative to network time via ntpdate.

    Was this page helpful?
    Tags: (Edit tags)
    • No tags
    FileSizeDateAttached by 
     Battery Backed Clock 1.JPG
    No description
    232.91 kB18:38, 14 May 2013bradActions
    Comments (0)

     
    Powered by MindTouch Core