Go Down

Topic: ds3234 routine walkthrough and eeprom store (Read 874 times) previous topic - next topic

rsqdivr

First post so sorry for the ignorance.   :smiley-sweat:

I have a couple projects where I'm using the ds3234 for a RTC.  I can set the time and display it fine using the sparkfun code.
I have modified it slightly so I can manipulate the data individually.  This function, I would call to simply get the "minutes" data.

Code: [Select]
String ReadMin(){
        String tempTime;       // I added these
        String mn_time;         // minutes data returned to caller

// this is the original source routine for getting all the time/date info
int TimeDate [7]; //second,minute,hour,null,day,month,year
for(int i=0; i<=6;i++){
if(i==3)
i++;
digitalWrite(cs, LOW);
SPI.transfer(i+0x00);
unsigned int n = SPI.transfer(0x00);       
digitalWrite(cs, HIGH);
int a=n & B00001111;   
if(i==2){
int b=(n & B00110000)>>4; //24 hour mode
if(b==B00000010)
b=20;       
else if(b==B00000001)
b=10;
TimeDate[i]=a+b;
}
else if(i==4){
int b=(n & B00110000)>>4;
TimeDate[i]=a+b*10;
}
else if(i==5){
int b=(n & B00010000)>>4;
TimeDate[i]=a+b*10;
}
else if(i==6){
int b=(n & B11110000)>>4;
TimeDate[i]=a+b*10;
}
else{
int b=(n & B01110000)>>4;
TimeDate[i]=a+b*10;
}
}
        tempTime.concat(TimeDate[2]);
        tempTime.concat(":");
        tempTime.concat(TimeDate[1]);
        tempTime.concat(":");
        tempTime.concat(TimeDate[0]);

        mn_time = TimeDate[1]; 
        return(mn_time); 
}


The troubles I'm having  are:
1.)  I don't really understand what the routine is actually "doing".  I can tell it's some bitwise work but I don't follow it.  For simple displaying of date/time, it doesn't matter.  I just know that (mn_time) and (tempTime) will be the strings I need. 
2.)  I'd like to write this info to EEPROM on my UNO but the strings are all larger than 1 byte, so how is the best way to write this data to eeprom?  Break it into multiples and just keep track of what info went to which address? or is there some simple routine for handling such conversions?

Thanks for the help.   :)

rsqdivr

Also, I'm interested in having an interval timer.  Something like, interrupt every 5 minutes, etc.

robtillaart


check - http://arduino.cc/playground/Main/MsTimer2 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

And ditch those Strings. You KNOW how much space is needed to hold a date or time in the format you want. Use a char array of that size, instead.

Go Up