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
{
Serial.begin(9600);
}
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();
ds.select(ibutton); // select scanned device addr
ds.skip(); // skip ROM
delay(1000);
// ********* TESTING ********
// ds.reset();
// ds.select(ibutton);
// ********** END ***********
ds.write(0x66); // read clock 66h
ctrl = ds.read(); // 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);
Serial.println();
rtc = ((uint32_t)ds.read()); //LSB
rtc |= ((uint32_t)ds.read()) << 8;
rtc |= ((uint32_t)ds.read()) << 16;
rtc |= ((uint32_t)ds.read()) << 24; //MSB
Serial.print("RTC data is: ");
Serial.print(rtc, HEX);
Serial.println();
ds.reset(); // stop receiving clock data
Serial.println();
}
When running as above, I get the following debug output to serial:
Presense indicator: 1
Control byte is: FF
RTC data is: FFFFFFFF
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.