Go Down

Topic: Arduino Due DS3231 (Read 908 times) 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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy