Ported: JChristensen/DS3232RTC

Please do not post requests
User avatar
ahull
Posts: 1663
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Ported: JChristensen/DS3232RTC

Post by ahull » Mon May 09, 2016 11:56 am

Pito wrote:@ahull - nice project!
I like the DS3231 module as it is precise - in 6months it did +6sec, so I added Aging reg writing to the lib and with +4 written into it may happen I will do a single second off per year :)
Oscillators with 32kHz fork resonator - you must tune them - a pF capacitance change does few seconds a day, moreover there is no temperature compensation. Of course, still ok for most apps.
Good points, you can of course tune the STM32F103 with its internal registers, but that still wont get you anywhere near the seconds per year mark.

For anything more precise, GPS or NTP (using an ESP8266 perhaps) or "mobile phone time" are probably the simplest options. If your device is designed to sit around in a remote location and know the time reasonably precisely, (sunset is a fairly long event, so a few seconds here or there 'aint going to be very important), then the STM32F10X is perfectly adequate.

I think I was getting of the order of a few seconds per week, comparable or better than most cheap wrist watches.
- Andy Hull -

User avatar
Pito
Posts: 1628
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Ported: JChristensen/DS3232RTC

Post by Pito » Mon May 09, 2016 3:30 pm

I like this video:
https://www.youtube.com/watch?v=Jp2BOBIzSE0
and my wish list :)
DS3231tuning.JPG
Pukao Hats Cleaning Services Ltd.

User avatar
ddrown
Posts: 146
Joined: Sat Jan 09, 2016 4:49 am

Re: Ported: JChristensen/DS3232RTC

Post by ddrown » Tue May 10, 2016 3:08 pm

ahull wrote:For anything more precise, GPS or NTP (using an ESP8266 perhaps) or "mobile phone time" are probably the simplest options.
I have some code for the NTP+ESP8266 combo if you're interested in going in that direction. My latest writeup on it: https://blog.dan.drown.org/binary-clock-update-2/

The summary of those results is the esp8266's clock is within +/- 10ms and +/- 10ppm of true time.

Code starts here, with links to the libraries it uses: https://github.com/ddrown/binary-clock

doctorlivesey
Posts: 1
Joined: Fri Oct 28, 2016 1:37 pm

Re: Ported: JChristensen/DS3232RTC

Post by doctorlivesey » Tue Nov 22, 2016 10:34 pm

Kenjutsu wrote:I ported the DS3232RTC library of JChristensen and tested it with a DS3231 AT24C32 IIC module precision Real time clock module memory module Arduino. I only tested the SetSerial.ino example program.
The port can be found here: https://github.com/KenjutsuGH/DS3232RTC.git
Hello,

I downloaded this library and tested it with my project on Maple Mini (i2c #1, D15 and D16) with DS3132. Great job!
Mentioned example SetSerial.ino started to work immediately!

Then I tested built-in termometer.
Everything OK for positive Celsius temperatures, but for below zero C temperatures it started to show 255 C... 250 C... and so on.

This link describes the problem:
https://arduinodiy.wordpress.com/2015/1 ... re-sensor/

Need to detect the highest bit of TEMP_MSB after reading ( rtcTemp.b[1] = readRTC(TEMP_MSB); )

I changed the library a little bit:

Code: Select all

/*----------------------------------------------------------------------*
 * Returns the temperature in Celsius times four.                       *
 *----------------------------------------------------------------------*/
int DS3232RTC::temperature(void)
{
    union int16_byte {
        int i;
        byte b[2];
    } rtcTemp;
    
    rtcTemp.b[0] = readRTC(TEMP_LSB);
    rtcTemp.b[1] = readRTC(TEMP_MSB);

   if (rtcTemp.b[1] >> 7 != 0) {
      rtcTemp.b[1] ^= 0b11111111;
      rtcTemp.b[1] += 0x1;
      return -1 * rtcTemp.i / 64;
    }
    else {
      return rtcTemp.i / 64;
    }
}
The following :

Code: Select all

 if (rtcTemp.b[1] >> 7 != 0) {
      rtcTemp.b[1] ^= 0b11111111;
      rtcTemp.b[1] += 0x1;
      return -1 * rtcTemp.i / 64;
    }
    else {
      return rtcTemp.i / 64;
    }
instead of simple return code:

Code: Select all

 return rtcTemp.i / 64;

And now it shows correct negative Celsius temperatures!

acronis
Posts: 156
Joined: Thu Mar 02, 2017 12:32 pm

Re: Ported: JChristensen/DS3232RTC

Post by acronis » Fri Mar 17, 2017 7:20 am

Hello !

my project

#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include "Time.h"
#include <TimeLib.h>

time_t t1;
time_t t2;

tmElements_t tm;


t1=RTC.get();
t2=now();



t2 ОК. returns the time in seconds

t1 - returns ZERO.


what's wrong ? why zero ???

modul DS3231

сlock is right.the clock is right

if
RTC.read(tm);
int hh = tm.Hour;
int mm = tm.Minute;
int ss = tm.Second;

everything is fine.then everything is fine
hh - contains hours
mm - contains minute
ss - contains second

t1=RTC.get();
t1 - returns ZERO ????

why ? what's wrong

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: Ported: JChristensen/DS3232RTC

Post by martinayotte » Fri Mar 17, 2017 2:58 pm

If you look at the DS3232RTC library code, it is returning 0 if it is not able to read the RTC on I2C bus.
So, you need to debug that ... Maybe your wiring is wrong, maybe you forgot to have pull-ups, etc ...

acronis
Posts: 156
Joined: Thu Mar 02, 2017 12:32 pm

Re: Ported: JChristensen/DS3232RTC

Post by acronis » Sat Mar 18, 2017 12:31 am

No.
the clock is right.
if you disconnect the power wire from the clock module - clock-stop.
If you set a time and do not remove the battery from the module , the time is read correctly.
But if the battery is removed - the time is reset to 1970.
I think that the problem is to link new libraries<TimeLib.h> and <DS3232RTC.h> .
https://github.com/PaulStoffregen/Time

User avatar
Naguissa
Posts: 74
Joined: Sun May 03, 2015 10:38 am
Location: Barcelona, Spain
Contact:

Re: Ported: JChristensen/DS3232RTC

Post by Naguissa » Sat Mar 18, 2017 1:33 am

I've created a very simple rtc library, uRTCLib. If your library is reading rtc correctly check math operations, probably there is a type problem (32 bits vs 8 bits operation).

Post Reply