View Full Version : iButton

05-18-2005, 08:40 PM
Remember this?

Does anyone have a code for tranlating hh/min/sec time from a Dallas 1994 iButton?
Just want to have an RTC addition to the project (BS2p40 with serial LCD), and I have
some iButtons on the shelf...

thanx, johnny"

well, so far I can get the time data, in a form of incrementing sec counter,·but....

OWOUT OWpin, %0001, [SkipROM, ReadMemory,2,2]
OWIN OWpin, %0010, [SPSTR 5]
SEROUT LCD_serOUT, LCD_baud, [27,4,DEC2 (temp/3600),58,DEC2 (temp/60)//60,46,DEC2 temp//60]
(first byte:1/256th seconds, next four bytes are the sec counter)
so something like this, but the 16 bits are not enough to count 24 hours in seconds, so I would need the
next 8 bits also from the stream. (GET 3, ....)

anyone got a nice solution or idea?


Chris Savage
05-18-2005, 09:33 PM

·· Tech Support recently answered this question in another thread (In fact it was you who asked for the same code before), but I will repost the link here for you.· We have a book available as a free download in PDF format from our website that has code for the BS2p for this device.· You can find it here:


Page 172, according to another Tech.· Also see Page 179.· Good luck!

The original thread is here: http://forums.parallax.com/showthread.php?p=535514

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Jon Williams
05-18-2005, 09:35 PM
Looking at the docs, the DS1994 stores time in seconds: the first four bytes form a 32-bit whole seconds value (0 to 4294967296), the final byte is fractional seconds (1/256). My point is that you will need another approach for your calculations. The thing about the DS1994 is not a real-time-clock in the sense of the DS1307 and others that actually tract time elements (hours, minutes, seconds) is separate registers.

Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA

05-19-2005, 01:28 AM
Okay, I read the BS2p book, but that will not solve my problem. Thanx to the book, now I can get the info from the iButton, but still cannot make a clock from it. If I could follow the sec counter, I could make the calculations, and display the time.

So I ask it an other way: how to handle a 32-bit counter with the BS2p?

thanx, johnny

Chris Savage
05-19-2005, 02:21 AM

·· Jon has provided you with the information you need in addition to what's in the book.· You're going to need some math.· http://forums.parallax.com/images/smilies/wink.gif

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Jon Williams
05-19-2005, 03:26 AM
Tracy Allen has some 32-bit routines on his web site: http://www.emesystems.com/BS2math6.htm.

Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA

05-23-2005, 08:21 PM
Thanx Jon, nice webpage!·http://forums.parallax.com/images/smilies/smilewinkgrin.gif

Hope I'll find some·guidelines there...
By the way, I prefer the iButton over the 1302 (which I don't have yet...),
it contains the backup battery already, and only needs 1 communications pin.
And easier to mount on a proto board.

Just have to find a way to translate 32-bit counter into 24h clock (Date is
not necessary...)

greetings, johnny

Jon Williams
05-23-2005, 09:46 PM
Since you're just wanting time you might consider keeping the value of the counter within the limits of 16-bit (word) variable.· This would let you track hours, minutes, and seconds for a 12-hour period.· Your software could keep track of AM/PM.· If you do this, the math is quite simple:

· hours = counter / 3600
· mins = counter / 60
· secs = counter // 60

When the counter rolls past the 12-hour mark of 43,200 you can "fix" the clock by doing this:

· counter = counter // 43200
· ampm = ~ampm

... then write the counter back to the DS1994

Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA

05-23-2005, 10:43 PM
Another solution could be to get a 'ThermoChron' (DS1921) iButton...

They have a RTC with YYMMDDHHMMSS format...
(Well, actually, it's in BCD format, so is REAL easy to transfer to an LCD, but a bit more work if you want to do any calculations)
Accuracy is given as +/-2minutes/month.

The 512Bytes general purpose memory is just a bonus...

05-24-2005, 02:28 PM
Come on! Why didn't I know about 1921 before http://forums.parallax.com/images/smilies/idea.gif ??
I also have one on the shelf...http://forums.parallax.com/images/smilies/yeah.gif
Thanx for the idea!

This is the way I approached, except after the sec and min divisions
I shifted the 16 bit number by 1 bit to the right, and shifted in the
first bit from the next byte, to have 24 hr counter.
Before doing this, I had to add an offset, to the counter, to have the
correct time. But this did not work...
Your point is good though, to WRITE BACK!!!! This should solve it.
Start from 0, no offsets, just basic divisions.

When I'm done with both this, I'll post it ;-)

br, johnny


05-25-2005, 01:12 PM
wow... now I am working on writing info back to the iButton.

Hope I can do it ;-)

Self-trained iButton guru-ness, here I come! http://forums.parallax.com/images/smilies/yeah.gif