Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Interfacing / Re: 1 wire/RTC iButton on: July 29, 2009, 11:11:20 am
Any suggestions? Looking like I'll need to use the DateTime software library for the time being smiley-sad
2  Forum 2005-2010 (read only) / Interfacing / Re: 1 wire/RTC iButton on: July 28, 2009, 12:48:04 pm
Still struggling with this, so tidied up my code at lunch and tested when I got home:

#include <OneWire.h>

OneWire  ds(8);  // on pin 8

byte ibutton[8] = {0x24, 0x35, 0x61, 0x33, 0x00, 0x00, 0x00, 0x01};

void setup() // run once, when the sketch starts



void loop() // run over and over again

 int present;  

  present = 0;

 byte ibutton[8] = {0x24, 0x35, 0x61, 0x33, 0x00, 0x00, 0x00, 0x01};
 uint8_t ctrl;          // control byte
 uint8_t ctrlout;        // control byte - used for write
 uint32_t rtc;      // 32bit for clock data

present = ds.reset();            // bus master sends reset - returns 1 if present, 0 if not

Serial.print("Presense indicator: ");
Serial.print(present, DEC);
Serial.println();;      // select scanned device addr
ds.skip();                  // skip ROM


// ********* TESTING ********
// ds.reset();
// ********** END ***********

ds.write(0x66);            // read clock 66h

ctrl =; // read control byte
                  // control byte will be needed for other operations - for example, to set the RTC!

// print the control byte as HEX

Serial.print("Control byte is: ");
Serial.print(ctrl, HEX);

rtc = ((uint32_t); //LSB
rtc |= ((uint32_t) << 8;
rtc |= ((uint32_t) << 16;
rtc |= ((uint32_t) << 24;  //MSB

Serial.print("RTC data is: ");
Serial.print(rtc, HEX);

ds.reset(); // stop receiving clock data



When running as above, I get the following debug output to serial:

Presense indicator: 1
Control byte is: FF

When I uncomment the lines after the ****** TESTING **** comment I get the following:

Presense indicator: 1
Control byte is: 50
RTC data is: 55555555

The value for the control byte isn't as expected (doesn't match up to possible bit settings in the datasheet)

I'm missing something here, just not sure what. My 1 wire bus seems to be setup (as if I take the iButton RTC out and wire for a DS18B20 sensor with some code) it works. The scan routine I've used from the example code picks up the device id too.

Any assistance greatly appreciated! Thanks.
3  Forum 2005-2010 (read only) / Interfacing / Re: 1 wire/RTC iButton on: July 28, 2009, 03:19:14 am
Quick bump and a note to mention I've had no issues reading from the DS18B20 temperature sensors on my 1 wire setup.

4  Forum 2005-2010 (read only) / Interfacing / Re: 1 wire/RTC iButton on: July 27, 2009, 05:13:51 pm
Well, I've added an additional ds.reset and before I issue the 0x66 - this seems to work better as I'm getting different data back now.

As the contents of the 5 bytes doesn't seem to change, I don't think that the oscillator has been started.

I've had a dig around and can't seem to find an example of how to set the OSC bit on... the datasheet says the following:
The Write Clock command is used to set the real-time clock counter and to write the device control byte.
After issuing the command, the bus master writes first the device control byte, which becomes
immediately effective. After this the bus master sends the least significant byte through the most
significant byte to be written to the real time clock counter. The new time data is copied from the
read/write buffer to the real time clock counter and becomes effective as the bus master generates a Reset
Pulse. If the oscillator is intentionally stopped the real time clock counter behaves as a 4-byte nonvolatile

So, I know I need to issue 0x99... but what next?
5  Forum 2005-2010 (read only) / Interfacing / Re: 1 wire/RTC iButton on: July 27, 2009, 04:07:24 pm
Excuse me ignorance, but how would I debug this?

As I make it from the datasheet, I should get 5 bytes back - 4 bytes of RTC and 1 control byte - so 32 bits + 8 bits?

Thanks for the quick response by the way smiley
6  Forum 2005-2010 (read only) / Interfacing / 1 wire/RTC iButton on: July 27, 2009, 03:38:42 pm

I'm new to the world of Arduino and struggling to get my iButton RTC up and running. The iButton is a DS1904 - 1 wire interface with xtal on board.

I wrongly assumed it would be as simple as building a base from some existing 1wire examples, for the last few nights I've been pulling my hair out!

I can search the bus and get the 8 byte device address.

From looking at the datasheet I need to send a bus reset, send 0xCC (to skip ROM CRC check) then send 0x66 to read the clock then read back the clock data.

So I've built the following code:

byte ibutton[8] = {0x24, 0x35, 0x61, 0x33, 0x00, 0x00, 0x00, 0x01};

ds.reset();            // bus master sends reset;      // select scanned device addr
ds.write(0xCC);         // skip rom CCh


ds.write(0x66);            // read clock 66h

for (byte i=0;i<32;i++)      {      //get data

      data =;
      Serial.print (data, HEX);            // debug

And this is where I get a bit stuck!
The debug print just throws back FF FF FF FF etc...

It did dawn on me that I probably need to turn on the internal oscillator and set the clock to '0' - but I'm a bit sketchy on how to push that to the iButton.

Apologies for my newbie-ness but I'd rather work at this that take the easy option and buy a prebuilt board from sparkfun etc!

Any tips would be greatly appreciated.
Pages: [1]