DS3231 RTC module - help with RAM usage.

I bought a few DS3231 RTC modules. They are working better than the "TINY RTC" ones.

I am working on a project now and it is nearly complete but I am stuck with accessing the RAM on the chip.

I downloaded the DS3232-Master library (I believe they are 99% compatible) and was looking through the data sheet.

There is a small amount of RAM in the chip starting at address 0x14 (or 20 decimal).

I read the RAM and get either 127 or 255. More on that later.

I then WRITE my value to it, and expect to read back that value.

Alas I get either 255 or 127 back.

This is the line:

DLS_Flag_Addr = 20;
DLS_Flag = 1;

and all the includes, etc are set.

RTC.writeRTC(DLS_Flag_Addr, DLS_Flag);

Is it I am missing something or just doing it "wrong"?

Thanks in advance.

What do you want to store on the clock? Why not store that data on the Arduino?

Hmm, there is no RAM space on the DS3231, only on the DS3232 :slight_smile:

Here is the datasheet of the DS3231: http://datasheets.maximintegrated.com/en/ds/DS3231.pdf

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. :slight_smile:
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

1 Like

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.

Now if I could just get mine working! :stuck_out_tongue:

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);
}

Hello,

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.

// DS3232 Register Addresses
#define RTC_SECONDS 0x00
#define RTC_MINUTES 0x01
#define RTC_HOURS 0x02
#define RTC_DAY 0x03
#define RTC_DATE 0x04
#define RTC_MONTH 0x05
#define RTC_YEAR 0x06
#define ALM1_SECONDS 0x07
#define ALM1_MINUTES 0x08
#define ALM1_HOURS 0x09
#define ALM1_DAYDATE 0x0A
#define ALM2_MINUTES 0x0B
#define ALM2_HOURS 0x0C
#define ALM2_DAYDATE 0x0D
#define RTC_CONTROL 0x0E
#define RTC_STATUS 0x0F
#define RTC_AGING 0x10
#define RTC_TEMP_MSB 0x11
#define RTC_TEMP_LSB 0x12
#define SRAM_START_ADDR 0x14 // first SRAM address
#define SRAM_SIZE 236 // number of bytes of SRAM