PaulS:
What do you want to store on the clock? Why not store that data on the Arduino?
Your question isn't really any answer to the original question, I'd say the guy wants to store something in RTC RAM, who are we to say he should not do that.
Anyhow, ther eis a very good reason to store something in the non volatile RAM on the RTC, as opposed to EEPROM on the Arduino.
The Arduino EEPROM namely has a finite number of write operations, while the RTC RAM supposedly hasn't. So with writing to EEPROM you are in fact wearing out your Arduino.
Sure a few times doesnt matter, but maybe the guy wants to do many writes and therefore prefers RTC NVRAM
While the DS3231 [[[CHIP]]] doesn't have ram in it, many Arduino MODULES of the same name do(a cause of much confusion throughout the web). The ZS-042 module shown below is one example and has an Atmel 24c32 sram chip.
The built in EEPROM is a limited write device with a limit of ~100k writes unlike the SRAM chip which is designed to be used dynamically. Info on that chip can be found here: http://www.atmel.com/images/doc0336.pdf
I looked at the DS3232 library and I don't think it's quite right. You might try looking over the DS1307 library and be careful to check the addressing, both at boot time (I think it's 0x57 for the zs-042) and internal address limits against info for your card.
I know this is an old post, but I needed to save a few bytes of a count in case the power fails, as I do not use the alarms, I can save some data in these addresses.
Datasheet pg 12:
Alarm 1 can be set by writing to registers 07h to 0Ah. Alarm 2 can be set by writing to registers 0Bh to 0Dh.
rtek1000:
I know this is an old post, but I needed to save a few bytes of a count in case the power fails, as I do not use the alarms, I can save some data in these addresses.
Successfully tested on ds3231 and nano (328), when removing the power supply, the value of i and j is saved and, when the count is restarted, it resumes the last saved value:
(Check the datasheet for each address bit before deploying)
/*
* TimeRTC.pde
* Example code illustrating Time library with Real Time Clock.
* This example is identical to the example provided with the Time Library,
* only the #include statement has been changed to include the DS3232RTC library.
*/
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <TimeLib.h> //http://www.arduino.cc/playground/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
byte i = 0,
j = 0;
void setup(void)
{
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
i = RTC.readRTC(7);
j = RTC.readRTC(8);
}
void loop(void)
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(void)
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(' ');
Serial.print(day());
Serial.print(' ');
Serial.print(month());
Serial.print(' ');
Serial.print(year());
Serial.print(' ');
RTC.writeRTC(7, i--);
Serial.print(RTC.readRTC(7));
Serial.print(' ');
RTC.writeRTC(8, i--);
Serial.print(RTC.readRTC(8));
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(':');
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
Just wanted to add some information about the addresses.
After spending some time trying to figure out why I was getting wrong results with some addresses and correct ones with others, I went to see the library. Even though "The valid address range is 0x00-0x12", some are used for other purposes.
While trying to write on addresses 0 to 6, I was even changing the date and time mistakenly.
The following list, from the library, made it clear what the mistake was...
Apparently, you should only use the addresses destinated to the alarms, 7 to 13 (0x07-0x0D). I used them without a problem. If you are using the alarms also, I don't know if any of the other addresses (0x0E-0x14) can be used.