Hardware Reference
In-Depth Information
Program ds1307set.c (executable ds1307set ) is used to reset the RTC to a new date/
time value of your choice. For example:
$ ./ds1307set 20130328215900
2013-03-28 21:59:00 (Thursday)
$
This sets the date according to the command-line value, which is in
YYYYMMDDHHMMSS format.
Once the RTC date has been established, you can use the executable ds1307get to
read back the date and time:
$ ./ds1307get
2013-03-28 22:00:37 (Thursday)
$
In this case, a little time had passed between setting the date and reading it. But we
can see that the clock is ticking away.
If you don't like the date/time format used, you can either change the source code or
set the environment variable DS1307_FORMAT . For example:
$ export DS1307_FORMAT="%a %Y-%m-%d %H:%M:%S"
$ ./ds1307get
Thu 2013-03-28 22:03:38
$
For a description of the date/time format options available, use this:
$ man date
The setting of DS1307_FORMAT also affects the display format used by ds1307set .
The Ultimate Test
The ultimate test is to shut down the Raspberry Pi and turn off its power. Wait a minute
or so to make sure that all of the power has been drained out of every available capacitor.
Then bring up the Pi again and check the date/time with the program ds1307get . Did it
lose any time?
The Startup Script
To put the RTC to good practical use, you'll want to apply ds1307get at a suitable point in
the Linux startup sequence. You'll need to wait until the appropriate I2C driver support
is available (or can be arranged). You'll need to develop a short shell script, using the
 
Search WWH ::




Custom Search