Monday, November 16, 2009

DS32C35 Real-time Clock Chip Success

I've been breadboard-testing the DS32C35 RTC after soldering this SOIC-20 onto a sparkfun breakout board, and I'm happy with what I've got: for Arduino use, everything 'just works'.

The beauty of this chip and its siblings in the Maxim line is that it comprises its clock crystal and it has some intelligence on board that keeps the clock highly accurate. This particular version includes 8 kB of FRAM, which unlike EEPROM can be read written an unlimited number of times. Both the RTC and the FRAM are accessible through the I2C line.

First the RTC. Not being interested in anything but the date and time, I was able to use the DS1307 library to access this RTC, since its I2C address is the same one used by other Maxim chips like the DS1307. You don't need to seed the RTC for it to start going, so it's easy to see if the oscillator is working or not.

Here's a short program I used to test the above library and to seed the data.

#include <Wire.h>

#include <DS1307.h>
#define TIMEOUT 30 * 1000

void setup() {
  Serial.begin(57600);
}

void loop() {
  if (Serial.available() > 0) {
    char value = Serial.read();
    if (value == 'T') {setTime();}
    if (value == 'R') {sayTime();}
    if (value == 'A') {Serial.println("Hi there");}
  }
}

boolean setTime() {
   //9:55:12 am on Christmas Day, 2009 //09122509065512
 Serial.println("TZ");
 long startTime = millis();
 while (Serial.available() < 14) {
    if (millis() - startTime > TIMEOUT) {
      Serial.println("F");
      return false;
    }
}
  char  twoDigits[2];
  readTwo(DS1307_YR,twoDigits);
   readTwo(DS1307_MTH,twoDigits);
   readTwo(DS1307_DATE,twoDigits);
   readTwo(DS1307_DOW,twoDigits);
   readTwo(DS1307_HR,twoDigits);
   readTwo(DS1307_MIN,twoDigits);
   readTwo(DS1307_SEC, twoDigits);
      Serial.println("T");
      return true;
   

}
  
  void readTwo(int value, char * twoDigits) {
  
    twoDigits[0] = Serial.read();
    twoDigits[1] = Serial.read();
    twoDigits[2] = '\0';
    Serial.println(twoDigits);
    
    RTC.set(value, atoi(twoDigits));
 
}
  
  void sayTime() {
    Serial.print(RTC.get(DS1307_YR,true));
    Serial.print(" ");
    Serial.print(RTC.get(DS1307_MTH,false));
    Serial.print(" ");
    Serial.print(RTC.get(DS1307_DATE,true));
    Serial.print(" ");
    Serial.print(RTC.get(DS1307_HR,true));
    Serial.print(":");
    Serial.print(RTC.get(DS1307_MIN,true));
        Serial.print(":");
        Serial.println(RTC.get(DS1307_SEC,true));
  }

Second, the FRAM. This, too, I was able to access through pre-existing code which I'd used for a 24LC512 chip.

The DS3232 is a clock-only version of this chip in a SOIC-16 format.

No comments:

Post a Comment