I'm doing some experiments with this chip, my setup is a breadboarded atmega328P-PU running @ 8MHz with the internal oscillator, the board is powered @ 3.3V and everything runs fine except that I cannot set (or maybe get?) the correct year from the RTC.
I modified the RTClib to support theDS1388 as follows:
but all I get, whatever the year I set is always 2165 (end of the world?)
It comes from 2000 + 165 (converted from BCD) ... 165 must have something special: is the value I got for all bytes when I ran the unprogammed RTC the first time.
From the datasheet, the only difference from the DS1307 (which works perfectly @ 5V in the same circuit) is the first address which contains hundred seconds in the DS1388, so I just ignored this byte and shifted all by one in respect to the DS1307.
Any idea or suggestion?
Might be a broken chip... but hour, minute, second, month and day works just fine.
My circuit has the arduino in a deep sleep, woken up every 60 seconds by the RTC interrupt, which then does some logging, and goes straight back to sleep. Nearly ripped my hair out trying to find out why this didn't work the way I wanted.
Here's what I learnt:
To initialise it in the first place the data sheet says it needs to be disabled before you can write to the watchdog time registers, then re-enabled.
//Disable the RTC watchdog first.
Wire.beginTransmission(0x68);
Wire.write(0x0c);
Wire.write(0x00);
Wire.endTransmission();
//Set the watchdog timer to 60 seconds
Wire.beginTransmission(0x68);
Wire.write(0x08);
Wire.write(0x00); //08h
Wire.write(0x60); //09h - time 60 seconds
Wire.write(0x00); //0ah
Wire.write(0x00); //0bh - clear the triggered bit.
Wire.endTransmission();
//Enable the watchdog timer in the RTC. 0x0c -> 0x03 (WDE and WDE/RST)
Wire.beginTransmission(0x68);
Wire.write(0x0c);
Wire.write(0x03);
Wire.endTransmission();
attachInterrupt(1, onWake, RISING); //here's my interrupt handler.
Once it wakes you up, you need to do the following to make it go off in another minute - if you don't, it will never fire again!
You need to re-specify the time, and clear the 'triggered' bit in the 0x0b register, then you can safely sleep, and it will wake you in another 60 seconds
//Reset the watchdog timer
Wire.beginTransmission(0x68);
Wire.write(0x08);
Wire.write(0x00); //08h
Wire.write(0x60); //09h - time 60 seconds.
Wire.write(0x00); //0ah
Wire.write(0x00); //0bh - clear the triggered bit.
Wire.endTransmission();
it would be nice if you could rename the class to match the chip DS1307 -> DS1388 and upload the code on github, I'm sure that somebody will cooperate to check and maybe improve the library.
I did wonder whether it might be better to adjust the class heirarchy a bit, and have a core DSRTC class, with two subclasses (DS1388 and DS1307) etc to improve code re-use.
One problem I've found with some libraries like the DS1307 is that it isn't maintained in simply one place. I wonder if the arduino 'core' project team has considered adopting it like the I2C libraries etc? If so, it'd be clear who owned it, and therefore who to submit patches to.
Your proposal makes a lot of sense!
Maybe not primary for code reuse but at least for interface reuse, so all those RTC's can be called in the same manner.
I could fork the original lib on github, add my modifications, and you can then add yours.
Or we can do the opposite: you fork (or just start a new repo if yours does not inherit from RTCLib) and I add my modifications (if needed).
I think that github is a very good way to distribute development efforts and maintain the code.
I don't think this lib will ever go into the Arduino core, there are so many chips out there that supporting them all would be a real nightmare for core maintainers.
It's very sensitive to any crystal instability, so touching the contacts of the crystal while it's running is enough to upset it and make isRunning() return false.
Problem fixed by coating those pins and the short length of track between them and the ds1388 with hot glue. Solved
I think "isRunning" doesn't exists anymore in the lib, to tell you the truth I was using an older version with isRunning already in place but when I forked I noticed that it has been dropped meanwhile.
We could add it back and ask for a merge (pull request in git jargon), it was definitely a useful function to initalize the clock with compile time when loading the sketch.