Using the RAM of DS3232RTC with Arduino Uno

Hello !

I am new on this forum. (but I already read some very interesting exchanges here)

My current project is to follow the curse of the sun during the day. For that I use an arduino Uno with a RTC (DS3231 or DS3232).

For the RTC I use the Library DS3232RTC-master of Jack Christensen.

My problem is that I cannot manage to register and read data using the RAM of the RTC module. :

static float Latitude, Longitude ; // (example of data Latitude=45.128 ; Longitude = -1.007 )

In the main loop :

I want either read variables through USB (no problem for that ) :blush: :

if (carlu1=='w') {

Serial.print(F(" Entrez Latitude,Longitude : "));

Attente6 :

if (Serial.available()<=0) goto Attente6; // attente données

delay (10);

Latitude = Serial.parseFloat();

delay (10);

Longitude = Serial.parseFloat();

delay (10);

then record the data in the RAM of RTC by using the following command :frowning: :

writeRTC(byte addr, byte *values, byte nBytes)

writeRTC(1, byte *values, 4)

either read in the RAM of RTC by using the following command :frowning: :

readRTC(byte addr, byte *values, byte nBytes)

I don’t manage to fill the 2nd parameter and I didn’t find any example of the use of these 2 commands on the net.

Someone can give an advice or propose an example ?

Thanks in advance for your help !

The RAM is accessed like all the clock registers.

The DS3232 provides 236 bytes of general-purpose battery-backed read /write memory . The I2C address ranges from 14h to 0FFh.

Are you using the appropriate addresses within that range?

a7

This library works great on tracking the sun, jpb10/SolarCalculator: Arduino library to calculate the times of sunrise, sunset, solar noon, twilight, the solar position and more. (github.com).

Thank you for your quick response.
My problem was indeed a wrong syntax.
The program runs correctly now with the following lines :
RTC.writeRTC(0x14,(uint8_t *)&Latitude, 4);
delay (20);
RTC.writeRTC(0x18,(uint8_t *)&Longitude, 4);
delay (20);
RTC.readRTC(0x14,(uint8_t *)&Latitude, 4);
delay (20);
RTC.readRTC(0x18,(uint8_t *)&Longitude, 4);
delay (20);

Cordially

Thank-you Idahowalker. I just downloaded the SolarCalculator library and tried it. It is very accurate and efficient.
I will use some of these functions to improve my project.
Greetings

1 Like

Hello,

For my project I first used a RTC DS1307 that worked quite well. As I needed more accuracy in time measurement, I wanted to change it with the RTC DS3232 that is temperature compensated.
I received recently the RTC DS3232 but I have no communication between arduino and the RTC.
I made a very simple circuit:
SDA -> A4
SCL -> A5
and even the examples given with the library don't work.
The RTC's battery is loaded.
I use the library DS3232RTC-master of Jack Christensen.
Someone can help to find the problem ?

What did the I2C scan report on the connected device?

I2CScanner - Arduino Reference

The DS3232 is not an I2C device. It's a SPI device.

1 Like

@ aarg : The DS3232 is a I2C device following the Data sheet :
datasheetDS3232.pdf (276,3 Ko)

@Idahowalker : I have installed the library & checked the i2C scan : there is no answer. It doesnt see the RTC.
Any idea will be welcome !

Post a few images of your project. Did you try using pullup resistors. Is your device an I2C device?

Problem is solved!
For an unknown reason the device itself was out of run.
I exchanged it with another one (I bought 2 DS3232 ) and now I2C scan is OK :

--- Scan started ---
I2C device found at address 0x68 !
--- Scan finished ---

I can continue my project :slight_smile:
Thank you for your help !

Oops I was thinking of the DS3234. Sorry!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.