Difference between revisions of "Adafruit: RTC DS1307"

From eLinux.org
Jump to: navigation, search
m
m
Line 2: Line 2:
 
[[Category:Adafruit]]
 
[[Category:Adafruit]]
  
[[File:DS1307 BBB.JPG|300px|Wiring for DS1307 RTC with Beaglebone Black.]]
+
[[File:DS1307 BBB.JPG|300px|framed|Wiring for DS1307 RTC with Beaglebone Black.]]
[[]]
+
 
== Overview ==
 
== Overview ==
  

Revision as of 03:03, 11 December 2013

Wiring for DS1307 RTC with Beaglebone Black.

Overview

Adafruit's DS1307 Real-Time Clock Breakout Kit uses a Maxim Integrated DS1307. The DS1307 can be used to store a the date and time. It may lose or gain 2 seconds a day.


Inputs and Outputs

The RTC must be powered from the BeagleBone's 5V supply (note it must be powered from the DC adapter, or else I2C bus will hang, as there is not enough current provided by the usb bus to power the RTC). The RTC uses an I2C interface to communicate with the BBB.

Bone Usage

On boot BBB is connected power from the DC power adapter, therefore it loads the correct /dev/rtc modules.


Pin mappings:

P9 pin # (BeagleBone pin) -> Panel pin (wire color)

1 (GND) -> GND

5 (VDD_5V) -> VCC 5 (VDD_5V) -> SQW (through 10k pullup resistor)

19 (I2C2_SCL) -> SCL

20 (I2C2_SCL) -> SDA


Clock_init.sh

This code was adapted from adafruit's sample code, and can be found at Alex Alvarez's github repository].


#!/bin/bash
a=$(date +%Y)

if [[ $a < 2013 ]]; then
	
	echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
	echo "Retrieving time from rtc"
	hwclock -s -f /dev/rtc1
	hwclock -w

	echo "Date has been read from RTC, and copied to system clock"
else
   # Assumes if date is correct on reboot, that you are connected to network
   echo "Fetching time from ntp server"
   $(/usr/bin/ntpdate -b -s u pool.ntp.org)  

   if [ -e /dev/rtc1 ]; then
     echo "Writing system clock to RTC"
     hwclock -w -f /dev/rtc1
   else
    echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
     echo "Writing system clock to RTC"
     hwclock -w -f /dev/rtc1
   fi
fi

# Sets time zone to Eastern (GMT -5)
$( ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime )
echo "The new date is:" $(date)