Go Down

Topic: isl1208 rtc arduino library wanted (Read 7 times) previous topic - next topic

Louie323

Today at 09:23 pm Last Edit: Today at 10:00 pm by Louie323
greetings all, I am interested in someone writing a simple arduino library for the isl1208 for personal use, available to anyone who might want it also. i will try to provide as much information as i can. this is a personal favorite of mine due to the alarm/int, and greater accuracy than the 1307. thank you in advance.

Datasheet here:
http://www.intersil.com/content/dam/Intersil/documents/isl1/isl1208.pdf

I can control it with the following code, but am confused on the hour setting. If i use any other format i get gibberish. a library would be much neater, than the code im using. i came up with the following code from the datasheet, but i am not skilled at coding so please forgive any errors that may be really obvious to the trained eye. thank you.

Code: [Select]

//device isl1208 address 0x6F
#include <Wire.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/interrupt.h>
byte seconds, hours, minutes, date, months, years, statusReg;

void setup () {
  Serial.begin(9600);
  Wire.begin();

  Wire.beginTransmission(0x6F);
  Wire.write(0x07); //status register
  Wire.write(0x90);  //
  Wire.endTransmission();

  /*readStatusReg(statusReg);
  Serial.print(statusReg,HEX); //should be 144/0x90
  Serial.println("h - status register");*/

/*
  //alarm setup
  Wire.beginTransmission(0x6F);
  Wire.write(0x08); //alarm register
  Wire.write(0xD0);
  Wire.endTransmission();
  Wire.beginTransmission(0x6F);
  Wire.write(0x0c); //seconds alarm register
  Wire.write(0xB0); //secs
  Wire.endTransmission();
  */
  
  
// set time
/*
   Wire.beginTransmission(0x6F);
   Wire.write(0x00); //seconds register
   Wire.write(decToBcd(30)); //secs
   Wire.write(decToBcd(46));//min
   Wire.write(B10000111); //hour 7
   Wire.write(decToBcd(13)); //date
   Wire.write(decToBcd(01)); //month
   Wire.write(decToBcd(15)); //year
   Wire.endTransmission();
   Wire.beginTransmission(0x6f);
   Wire.write(0x07); //status reg addr
   Wire.endTransmission();
   readStatusReg(statusReg); */
  
}

void loop () {
//readtime
  Wire.beginTransmission(0x6f);
  Wire.write(0x00); //status reg addr
  Wire.endTransmission();
  Wire.requestFrom(0x6f,6); // now get the 6 bytes of data...
  seconds=Wire.read();
  minutes=Wire.read();
  hours=Wire.read();
  date=Wire.read();
  months=Wire.read();
  years=Wire.read();
  
  //hours=hours & B01111111; // remove mil time bit
  bitClear(hours,7);
  hours=bcdToDec(hours);
  minutes=bcdToDec(minutes);
  seconds=bcdToDec(seconds);
  //Serial.print(hours/10%10);
  //Serial.print(hours%10);
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes/10%10);
  Serial.print(minutes%10);
  Serial.print(".");
  Serial.print(seconds/10%10);
  Serial.println(seconds%10);
  
  
  Serial.print(bcdToDec(months));
  Serial.print('/');
  Serial.print(bcdToDec(date));
  Serial.print('/');
  Serial.println(bcdToDec(years));
  delay(1000);

}

byte readStatusReg(byte val){

  Wire.beginTransmission(0x6f);
  Wire.write(0x07); // read status reg to clr bits
  Wire.endTransmission();
  Wire.requestFrom(0x6f,1); // now get the byte of data...
  statusReg=Wire.read();
  return(statusReg);

}


byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}







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