DS1307 problem and DS3231

Hello everyone,

I'm using library for reading and writing the DS1307 RTC. I'm planning to switch to DS3231 and I'm just wondering
if the same library will work. Does anyone tried this?
I just ordered my DS3231 board so I don't have it on hand yet.

The reason I'm planning to change to DS3231 is my DS1307 is not accurate. I got a drift of +1 second per hour!
That's 278 ppm, right? Whereas I've read it should be just 50ppm. I'm just testing on room temperature and temp seems
constant. My RTC board was manufactured here locally in the Philippines and crystal used is 32.768kHz with 12.5pF
loading capacitance according to the manufacturer.

I'm planning to use my Arduino to log data for at least 6 months so this drift will really mess up my data.
If the DS1307 library won't work with the DS3231, it would be nice if someone can point a decent library for the DS3231.

Thanks
Cheers

The I2C 'DS3231' interface is very straight forward and
virtually identical to the register addresses of the popular DS1337
and DS1307 RTCs, which means that existing code for the Arduino,
Basic Stamp, Cubloc, and other controllers should work with no modification.

http://playground.arduino.cc/Code/time

You don't say which DS1307 library you use, but If you just do basic setting and reading the time, then you should be OK. I've used the DS1307RTC library that comes with the Time library (linked by @BillHo above) and it works with the DS3231.

If you use the square wave output, the control register for that has a different address so that function would not be compatible. The clock halt bit is also in a different place, but that is probably of no practical significance unless you specifically use it for some reason.

Indeed one second per hour would be 278ppm, but even 50ppm would be a lot of drift given that most crystals are probably advertised as 20-30ppm. There is a lot of junk out there.

If you want to use the alarms or other functionality specific to the DS3231, I wrote this library that supports both DS3231 and DS3232. It's probably just one of dozens out there.

I got some cheap Chinese RTC with a DS3231N. I found I could read the time with the standard DS1307 lib, but I could not set the time. I had to use this:

to set the time. I didn't know about Jack's library or I would have tried it first.

DS3231_M_ is a version with a MEMS resonator, ±5ppm. Have not tried one personally, but I'd have thought it would have all been the same as the DS3231S or SN from a programming standpoint.

Pretty sure I have an N as in November, however the RTC is now soldered face down on my board so no way to check now! But I do know it has no 'S' at all.

Using the standard DD1307 lib, I can set the time on a ChronoDot, which has a DS3231SN. Dunno what's different from the SN chip to the N chip that breaks the DS1307 lib. At the time, I was under a tight deadline to finish the project so I didn't dig in to the registers to see what was going on.

This library
http://www.pjrc.com/teensy/td_libs_DS1307RTC.html
is fully compatible with DS3231 (I tested it)

Also you may look here for inspiration:
http://forum.arduino.cc/index.php?topic=190221.0

Thanks a lot guys.

I'm also using a Chinese RTC board from Aliexpress.

http://www.aliexpress.com/item/Mini-RTCpro-DS3231-High-Precision-Clock-Module-FZ0429-Free-Shipping-via-China-Post/767738088.html

I guess it will take a couple of days before I get my hands on it.
I really forgot where I downloaded my DS1307 library.
But basically the code is this

RTC.stop();
RTC.start();
time._hour = RTC.get(DS1307_HR,true); //read the hour and also update all the values by pushing in true
time._minute = RTC.get(DS1307_MIN,false);//read minutes without update (false)
time._second = RTC.get(DS1307_SEC,false);//read seconds
time._day = RTC.get(DS1307_DATE,false);//read date
time._month = RTC.get(DS1307_MTH,false);//read month
time._year = RTC.get(DS1307_YR,false); //read year

I'll be just using read all the time once I set the time correctly.

Hi Jack,

Thanks. I just left my DS1307 over the night and after 14 hours, it drifted +19 seconds! Way over the 278ppm.
Do you believe this is caused by a low quality crystal?

How was your experience with the DS3231? Does it live up to 2ppm?

tylernt:
I got some cheap Chinese RTC with a DS3231N. I found I could read the time with the standard DS1307 lib, but I could not set the time. I had to use this:

GitHub - trunet/DS3231RTC: An arduino library for DS3231 Real-time clock

to set the time. I didn't know about Jack's library or I would have tried it first.

Hi Tyler,

Where did you get your Chinese RTC?

I ordered mine from Aliexpress.

Mine came from DX.com, SKU 222910. The pic shows a DS3231SN but the board that arrived was just an N, no S. I'm happy with it so far once I got the time set.

DX also lists SKU 168974 but the battery on that one is not replaceable.

tylernt:
Mine came from DX.com, SKU 222910. The pic shows a DS3231SN but the board that arrived was just an N, no S. I'm happy with it so far once I got the time set.

DX also lists SKU 168974 but the battery on that one is not replaceable.

Oh

The SKU 168974 is the one exactly I ordered from Aliexpress!
I didn't read the battery is soldered onto the board. But I guess
it will give me almost a decade of lifespan, won't it?

davemac_314:
I guess
it will give me almost a decade of lifespan, won't it?

A few years, at least. The good news is, you can buy lithium coin cells with through-hole legs attached from places like Digikey, Mouser, and Newark. So you can still replace the cell if you're willing to desolder the old one.

Thank you all,

By the way,

Based on the schematic diagram found here (scroll down)

http://www.aliexpress.com/item/Mini-RTCpro-DS3231-High-Precision-Clock-Module-FZ0429-Free-Shipping-via-China-Post/767738088.html

The DS3231 is operating at 3.3V BUT the SDA and SCL are pulled up to 5V (Vcc), right?
Can I interface it directly with my Arduino's SDA and SCL?
Or do I need to use a logic converter?

I found this from the data sheet of the DS3231

15 SDA Serial Data Input/Output. This pin is the data input/output for the I2C serial interface. This open-drain pin
requires an external pullup resistor. The pullup voltage can be up to 5.5V, regardless of the voltage on VCC.
16 SCL Serial Clock Input. This pin is the clock input for the I2C serial interface and is used to synchronize data
movement on the serial interface. Up to 5.5V can be used for this pin, regardless of the voltage on VCC.

Since the DS3231's SDA and SCL are pulled up to 5V while Vcc is 3.3V, I guess it's ok. And I can directly connect it to my Arduino without using logic converter.

Let me know your thoughts guys.
Thanks

davemac_314:
Since the DS3231's SDA and SCL are pulled up to 5V while Vcc is 3.3V, I guess it's ok. And I can directly connect it to my Arduino without using logic converter.

It's OK for the DS3231, but not for the Arduino. Maximum voltage on AVR MCU pin is Vcc + 0.5V.

I'm not clear what the setup is, but if the Arduino is a 5V model, run the DS3231 on 5V too. If the Arduino is 3.3V, run the DS3231 on 3.3V. It's perfectly happy with either.

I have the same problem with a ds1307 - the time keeping is useless! I wonder if I should try and change the xtal?

Does anyone know if the GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library will work with a DS3231?

Thanks

dtokez:
I have the same problem with a ds1307 - the time keeping is useless! I wonder if I should try and change the xtal?

Temperature compensation is also a problem. You might reduce the drift with a new xtal, but unless the RTC always stays at exactly the same temperature, it's probably not worth the effort.

dtokez:
Does anyone know if the GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library will work with a DS3231?

Chips are compatible, so maybe yes. I tested another one library and it is comaptible:
http://forum.arduino.cc/index.php?topic=202909.msg1495853#msg1495853

Also you can use RTC chip without the library. It is not complicated, look into sketch:
http://forum.arduino.cc/index.php?topic=190221.0

can someone tell me how the pinlayout is of the RTC 3231N red fro DX, because there is not any information on the board, nor on internet.
Theo board has a 5 pin connector. some other RTC's have a 6 pin connector.
I also wonder about the battery, which happens to be a capacitor.
So how do I connect?