Pages: [1]   Go Down
Author Topic: Arduino Due DS3231  (Read 482 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 112
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there by any chance a DS3231 or equivalent library for the Arduino Due?
Logged

No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

0
Offline Offline
Full Member
***
Karma: 0
Posts: 112
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
}
« Last Edit: May 28, 2013, 08:27:05 pm by bastukee » Logged

No trees were harmed by the transmission of this message. However a few million electrons were temporarily inconvenienced.

Pages: [1]   Go Up
Jump to: