I2C RTC
From AlwaysInnovating
(This is a copy of my blog post at [1]. I hereby grant permission to use this content under the Creative Commons by-nc-sa license)
The Touch Book comes without a battery backed RTC, which means that the device will lose the correct time every power down. While this won't be much of a problem once power management works and the Touch Book stays mostly on it's quite annoying right now.
Contents |
Choice of RTC
There are several easy to use RTC chips with different interfaces available. Since the Touch Book uses I2C, and the I2C buses are easily accessible chosing a RTC chip with I2C interface appears to be the best option. This article demonstrates how to hook up a DS1307 to one of the Touch Books I2C buses.
Parts
You need:
- One DS1307
- One 3V Lithium Cell with at least 48mAh
- One 32.768 kHz quartz crystal
- Some wires
You should be able to get these components for about 3 Euros.
Hardware
Preparing the RTC
First you bend the pins of the crystal so you can put it on top of the DS1307 and solder it to X1/X2 (pins 1 and 2), and solder GND (pin4) to the battery's negative terminal:
Now mark pin 1 on your cable, and make a note which wire you'd like to use for which signal. In my setup the lines from right (1) to left (4) are:
Connect the cable to the DS1307: GND to the batteries negative terminal, SDA to pin 5, SCL to pin 6 and VCC to pin 8
Connecting to the motherboard
Use a small piece of cable to connect the battery's positive terminal with VBAT (pin 3), and mark the soldering points we want to use on the mainboard. The interesting pins from right (1) to left (8) are: USB 5V (1), used as power supply for the chip during normal operations, GND (4), SCL (5) and SDA (6).
Update: Since USB 5V is only available when the USB subsystem is loaded using it is not the best option. When using USB as power source you need a 1 second wait in the kernel modules initalization routine. Better options are:
A) soldering VCC to L21:
or B) soldering VCC to the unused pad of C209 closest to the inter-part connector / pad connected to U2 and C184:
(Board Rev.B1)
Disconnect your Touch Book from the power supply, unplug the internal battery, and carefully (preferably without accidentally swapping some lines) solder the wires to the mainboard (Update: The following pictures are for the version using USB for VCC. Better use 3 wires to the interpart connector, and a seperate wire from VCC to C209 or C184). After that you can turn on your Touch Book to test if everything works.
PCB plans
Plans for a very compact PCB version have been prepared. Fabricated boards can be ordered HERE
Initialization and Testing
You need to get the i2c command line utility from Gumstix to initialize and test the chip. You can use this version compiled for AI OS if you don't want to compile it yourself. Save the i2c program somewhere in the search path. My binary tries to open /dev/i2c-3, while the gumstick sources use i2c-0 by default. You'll need to adjust this if you use the sources.
To initialize the RTC and set the time to February 19th 2010, 00:51 do the following:
i2c --count=8 0x68 wb 0x0 0x0051000719021000
0x68 is the address of the chip, for the date format description please read the DS1307 datasheet (Table 2, Timekeeper Registers). If everything worked well you can now use watch to see the RTC counting seconds:
watch -n 1 i2c --count=8 0x68 readbyte 0
Once you're satisfied with the results you can stick the battery to the display's backside using some double sided adhesive tape. The attached chip fits nicely into one of the notches around the border:
Kernel setup
To use the chip as a RTC you can either apply my patch to the AI-OS tree and build your own kernel image, or download a patched uImage (latest AI git already contains support for the chip). Just copy the uImage over the one on the first partition of the SD card, and reboot.
The new DS1307 should show up as first RTC, the old TWL4030 as second:
$ dmesg|grep rtc [ 19.007293] rtc-ds1307 3-0068: rtc core: registered ds1307 as rtc0 [ 19.007324] rtc-ds1307 3-0068: 56 bytes nvram [ 19.007659] twl4030_rtc twl4030_rtc: rtc core: registered twl4030_rtc as rtc1 [ 19.007781] twl4030_rtc twl4030_rtc: Power up reset detected. [ 19.008148] twl4030_rtc twl4030_rtc: Enabling TWL4030-RTC. [ 19.273559] rtc-ds1307 3-0068: setting system clock to 2010-02-21 13:52:16 UTC (1266760336)
You can control both RTCs using hwclock, though the TWL4030 is mostly useless after the mod:
$ hwclock -f /dev/rtc Sun Feb 21 14:09:47 2010 0.000000 seconds $ hwclock -f /dev/rtc1 Sat Jan 1 00:17:32 2000 0.000000 seconds
For more information you can poke around in sysfs, interesting locations include /sys/bus/i2c/devices/ (3-0068 is the DS1307), /sys/bus/i2c/drivers/ and /sys/class/rtc/.










