Shop OBEX P1 Docs P2 Docs Learn Events
Driver for S-35390A RTC chip — Parallax Forums

Driver for S-35390A RTC chip

Roy ElthamRoy Eltham Posts: 2,998
edited 2013-12-06 13:25 in Accessories
Attached is a driver for the Real Time Clock chip on the Spinneret Web Server board.

You need to get the basic_i2c_driver file from the obex here: http://obex.parallax.com/objects/26/
Or alternatively you can use the pasm_i2c_driver from the obex here: http://obex.parallax.com/objects/611/ (you'll need to modify the OBJ section to change basic to pasm if you use this one)

What is implemented:
Setting and reading of date and time
Handling 12 hour or 24 hour mode (setting the time is always in 24 hour mode)
Setting Alarms and reading if they have occurred.
Reading and writing a user data byte that is retained across power cycles
Functions to get and set the Clock Correction register
Functions to get and set the 2 status registers (temporary)
I added a bunch of comments to explain more of what's going on

What is not implemented:
The user frequency stuff (drives the int pins)
There is a second byte of user data spread across 3 registers

Usage info:
You need to call start at the beginning of your program before calling anything else. Then call SetDateTime(...), SetTime(...), and/or Set24HourMode(...) as needed.

Use SetAlarm(...) to set either of the two alarms, and call DidAlarmOccur() to see if one of the alarms went off. You should call Update before calling DidAlarmOccur() (and at least once between calls to it also).

To read the date/time, first call Update, then call any of the GetXXXX functions.

Use SetUserData(value) to store and value := GetUserData to retrieve a byte of user data.

Note about clock correction:
You should read the datasheet for a detail description of what values to set on the clock correction register.

Note about the status registers:
You should read the datasheet and the comments in my code before you call any of the functions that deal with the status registers. In normal usage of this driver, you shouldn't need to call these functions, but I put them in for now since I haven't implemented everything yet.

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2010-11-13 12:34
    Roy Eltham wrote: »
    Attached is the first version of a driver for the Real Time Clock chip on the Spinneret Web Server board.

    You need to get the basic_i2c_driver file from the obex here: http://obex.parallax.com/objects/26/
    Or alternatively you can use the pasm_i2c_driver from the obex here: http://obex.parallax.com/objects/611/ (you'll need to modify the OBJ section to change basic to pasm if you use this one)

    What's implemented:
    Setting and reading of date and time
    Handling 12 hour or 24 hour mode (setting the time is always in 24 hour mode)
    Reading and writing a user data byte that is retained across power cycles

    What's not implemented:
    The alarm stuff.
    The user frequency stuff (drives the int pins)
    There is a second byte of user data spread across 3 registers

    Usage info:
    You need to call start at the beginning of your program before calling anything else. Then call SetDateTime(...), SetTime(...), and/or Set24HourMode(...) as needed.

    To read the date/time, first call Update, then call any of the GetXXXX functions.

    Use SetUserData(value) to store and value := GetUserData to retrieve a byte of user data.
    '
    Thanks for the RTC driver.
    '
    I just got My Spinneret, So I'm still reading, wiriing,etc.
    '
    This code will be very usefull.
    '
    Thanks Again
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-11-16 15:25
    Roy,

    Have you checked the accuracy of the real time clock on your board? I set the time on mine yesterday, and it gained 18 seconds in 24 hours. That works out to 208 PPM. I set the frequency adjustment register to compensate for the fast clock. I'll check it again tomorrow to see how close the time is.

    Dave
  • Roy ElthamRoy Eltham Posts: 2,998
    edited 2010-11-16 15:29
    I hadn't done that test and adjustment yet. I intend to write some code for my Spinneret to get the time from the internet periodically.

    Of course that only covers when it's turned on and connected to the internet, so I may need to adjust the correction register.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-11-16 20:20
    Slow down Roy! I'm still methodically hooking power to mine. :)

    Seriously, thanks for the code. :)

    OBC
  • Roy ElthamRoy Eltham Posts: 2,998
    edited 2010-11-17 01:31
    I updated the driver. The first post has the new version attached, and is updated with all the changes. I've only done basic testing of the new version, so please report any issues you find so I can get them fixed. Thanks!
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-11-17 08:18
    I checked the RTC on my board and it still shows the correct time after 16 hours. I am a bit concerned that I had to use the maximum negative clock correction value of $40, which is -195.3 PPM. I would be interested to hear if others have checked the accuracy of the RTC on their board.
  • Roy ElthamRoy Eltham Posts: 2,998
    edited 2010-11-17 09:22
    Dave Hein wrote: »
    I checked the RTC on my board and it still shows the correct time after 16 hours. I am a bit concerned that I had to use the maximum negative clock correction value of $40, which is -195.3 PPM. I would be interested to hear if others have checked the accuracy of the RTC on their board.

    According to my reading of the datasheet, if you wrote $40 to the register then that would be a correction of +6.1. For the -195.3 you'd need to write $04.

    I will test my RTC correction needs over the next few days.
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-11-17 12:31
    $40 is the bit-reversed version of the code for -195.3 PPM. The actual code on the wire would be $02, but I prefer to use the bit-reversed form that has the sign bit and most significants bits on the left rather than the right. I'm not sure why the chip designers decided to bit-reverse everything.
  • Roy ElthamRoy Eltham Posts: 2,998
    edited 2010-11-17 13:04
    Dave,

    Ok, yeah I am not sure why they bit reversed everything also. I get mixed up by it too (as you can see if put in $04 instead of $02. Have you tried the other option for correction that does it more often with a smaller range of adjustment?
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-11-17 15:34
    I need to use the maxium adjustment value, so I can't use the finer range adjustment. BTW, I checked the RTC again after 24 hours, and it's still correct to within one second.
  • Roy ElthamRoy Eltham Posts: 2,998
    edited 2010-11-17 16:32
    I just doubled checked the datasheet and the option you are using is the one that happens more often (every 20 seconds), the one with less range happens every 60 seconds. I had thought it was reversed of that. Oh well.
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-11-29 10:01
    I checked the RTC on my board again after I had set it almost two weeks ago. It only lost 8 seconds in 306 hours, which works out to -7.26 PPM. I changed the frequency adjustment from the maximum of -195.3 to 189.2 based on the latest measurement.

    I am still curious whether anybody else has looked at the accuracy of the RTC frequency, and whether their's is off by as much as mine. Is anybody working on getting the time from a time server? It would be nice to have the RTC automatically set and adjusted based on a time server.
  • BenjBenj Posts: 66
    edited 2011-05-31 11:13
    I tested my accuracy over the past 96 hours and it was 65 seconds fast (16.25 s/day). So, mine was off by ~189-192 ppm.

    Also, you have probably already seen it since this thread is over 6 months old, but Beau Schwabe posted some working code to set the RTC from internet SNTP time and I just added some code for the automatic adjustment for DST.

    http://forums.parallax.com/showthread.php?129435-DEMO-Using-SNTP-to-sync-the-Spinneret-s-on-board-RTC
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-06 13:25
    @Roy, I know this is a real old thread, but have you by any chance have written a C driver for this chip which could be used with the MGH Designs DNA-RTC board? I am not sure but I think the DNA-RTC board is still being sold, so there might be some common interest in this board and a C driver for it. I also noticed that the link to the I2C driver in the OBEX is broken.

    Ray
Sign In or Register to comment.