Go Down

Topic: Arduino Due DS3231 (Read 1 time) previous topic - next topic

bastukee

Is there by any chance a DS3231 or equivalent library for the Arduino Due?
No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

bastukee

#1
May 29, 2013, 03:01 am Last Edit: May 29, 2013, 03:27 am by bastukee Reason: 1
I believe I have solved my problem, I used this example, modified the deprecated wire commands and it works great.

http://www.l8ter.com/?p=417

I believe that the DS3231 should work with the DS1307 library, but I have not used it...

Code: [Select]
#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);
}
No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

jmc

Old post, but for what its worth, the DS1307 'RTClib' library does seem to work with the DS3231 on the due, at least initially....

ghlawrence2000

I too can confirm the DS3231 works fine with the DS1307 rtc lib, but might I also suggest an alternative as http://www.rinkydinkelectronics.com/library.php?id=73.

Regards,

Graham

rockwallaby

#4
Apr 07, 2015, 12:32 pm Last Edit: Apr 07, 2015, 02:24 pm by rockwallaby
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.

https://github.com/Tecsmith/DS3232RTC

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
Code: [Select]
extern DS3232RTC RTC_DS3232;

Source file, change same again at line 530:
Code: [Select]
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
http://paulalting.com

Go Up