Is there by any chance a DS3231 or equivalent library for the Arduino Due?
I believe I have solved my problem, I used this example, modified the deprecated wire commands and it works great.
I believe that the DS3231 should work with the DS1307 library, but I have not used it...
#include "Wire.h"
#define DS3231_ADDRESS 0x68
void setup(){
Wire.begin();
Serial.begin(9600);
}
void loop(){
printDate();
delay(1000);
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS3231_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS3231_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
printDigits(month);
Serial.print("/");
printDigits(monthDay);
Serial.print("/");
printDigits(year);
Serial.print(" ");
printDigits(hour);
Serial.print(":");
printDigits(minute);
Serial.print(":");
printDigits(second);
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
Old post, but for what its worth, the DS1307 'RTClib' library does seem to work with the DS3231 on the due, at least initially....
I too can confirm the DS3231 works fine with the DS1307 rtc lib, but might I also suggest an alternative as DS3231 - Rinky-Dink Electronics.
Regards,
Graham
Thanks Graham, I'll add that to my library list.
I'm coding a few projects up at present using the DS3231, for both DUE and AVR and have found two other sources for libraries.
First is what I use and is based on the DS3232 which is the same as DS3231 except the DS3232 has two programmable alarms and 263 bytes of read/write SRAM.
EDIT:
For above library, you will need to make a small change of instantiation in both the .h and .cpp file as follows:
Header, change at line 116, RTC to someting like RTC_DS3232
extern DS3232RTC RTC_DS3232;
Source file, change same again at line 530:
DS3232RTC RTC_DS3232 = DS3232RTC(); // instantiate for use
To avoid clash with SAM RTC.
Next is for DS3231, but may not tie in as well with the 'Time' library as the above library.
http://rweather.github.io/arduinolibs/classDS3231RTC.html
Paul