I am working with a Maxim DS2417 RTC with interrupt. I thought that i had got the control of the chip all sorted and doing what i wanted but now the RTC seems to have other ideas.
I got a little test program together that would write the data to the RTC and then use the output from the interrupt pin to pluse every second on pin 2 of the uno.
The program should count the pulses and when the count gets to 10 turn the LED on for 2 seconds then turn it off and reset the count.
That all worked the first time i tried it.
Disconnected the uno left it a day then plugged the uno back in and now not getting anything on the interrupt pin.
#include <OneWire.h>
// DS1904 Real Time Clock iButton I/O
OneWire ds(10); // on pin 10
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
byte i;
byte present = 0;
byte data[8];
byte addr[8];
if ( !ds.search(addr)) {
Serial.print("No more addresses found.\n");
ds.reset_search();
delay(500); // for readability
return;
}
Serial.print("ROM: ");
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
if ( addr[0] != 0x24) {
Serial.print("\t\tDevice is not a DS1904 family device.\n");
return;
}
/*
// write!
Serial.println("writing to RTC...");
present = ds.reset();
ds.select(addr);
ds.write(0x99,1); // write RTC - this is the write code
ds.write(0xAC); //This is the control byte. AC in hex = 10101100
//read the datasheet and you will see that this is important
//to start the internal osc's... Or to make the clock start
//counting seconds. --ril3y
ds.write(0x02); //0x02 is a random time set it with your own
ds.write(0x03); //same with this
ds.write(0x05); //this
ds.write(0x08); //and this
present = ds.reset();
delay(1500); // unknown if wait needed
*/
// read!
present = ds.reset();
ds.select(addr);
ds.write(0x66,1); // read RTC
Serial.print("PR: ");
Serial.print(present, HEX);
for ( i = 0; i < 5; i++) {
data[i] = ds.read();
}
Serial.print(" CTRL BYTE: ");
Serial.print(data[0], BIN);
Serial.print("\n\ttime: ");
for ( i = 1; i < 5; i++) {
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.println();
}
My point exactly. That was a hint. It needs to be. That function scans the bus and picks up the OneWire addresses of connected devices. You can call it iteratively to discover all the devices. If you only have one device, then once will do it.
You can see how it works by looking at the examples that come with the OneWire library. But, they call it on every pass through loop(). You don't need to do that. Once in setup() will work. You should also open up the source code for the OneWire library and see how it works.
Alternatively, with only one device on the bus, you might be able to use the Skip ROM technique. This is all covered in the DS2417 Datasheet. You need to read it.
The DS2417 datasheet states that when you issue the Write Clock command (0x99) you should follow it with 5 bytes: the Control Byte followed by 4 bytes for the clock setting. Finally, you should do a Bus Reset.
You're only sending the Control Byte and a then the reset. This may work, but you're using the device in an undocumented manner. You've essentially signed up to be an unpaid test pilot. Even though you're not actually using the clock part of the RTC, you should send it 4 dummy bytes (all zeros would probably work) after the Control Byte. Then send the reset.
Also, the 'ds.reset()' function returns a value that you're promptly ignoring. This return value provides useful information. You should read about it in OneWire.h. If a '1' is returned, all is well. But, a '0' signifies that a valid device was not found on the OneWire bus. If this happens, maybe you want your project to go into some kind of failure mode to let the user know that there's a problem? Maybe blink some lights or something.
Fix that stuff, put the code in 'setup()' and you should be good to go.
void setup()
{
present = ds.reset(); // Sets present to 0
ds.skip(); // Write to all addresses
ds.write(0x99); // Command to start writing to RTC
ds.write(0x8C); // Sets control bytes 1000 1100
ds.write(0x00); // Write time byte (time not used)
ds.write(0x00); // Same here
ds.write(0x00); // And here
ds.write(0x00); // And here
present = ds.reset(); // sets present to 1 if all ok.
// if not remains as 0