DS1302 - Setting the record straight...

I am a little lost regarding the DS1302....

The first and foremost thing is the discrepancy between the interface type......

Is this thing IC2 or not? The official Arduino side guide says (and I am quoting):

"It is not I2C, it's not OneWire, and it is not SPI.".

See here: Arduino Playground - DS1302

Yet, according to a couple other sites, I see they mention hooking this up via I2C (like: Add a Dallas DS1302 I2C Real Time Clock).

Further, I am having trouble finding coherent info regarding a single working library with good examples and documentation.

To top of the list, now that I am searching - I am reading this RTC essentially sucks and is practically useless.

Currently... I am fetching server time every hour (using an HTTP GET request via ES8266) and counting millis() to keep up with hours/minutes. This way, drift is never off too much (re-synced every hour).

Should I just keep what I have w/ server synced time? Or is this RTC worth my time/effort?

Currently, I am attempting to use it w/ the Time.h library (which is, itself not very clear) and cannot figure out how to even set the time from a unix timestamp.

If anyone can point me in the direction to something coherent and "in one place", that would help a lot.

Also - any input regarding my efforts with this chip are greatly appreciated as well.

Don't mistake the Arduino Playground content as being "official" just because the url contains arduino.cc. That is community generated content with a large variation in quality and accuracy. Anyone is welcome to edit or create Playground pages. That said, I also wouldn't rely on the official Arduino web site pages to be 100% accurate. There are certainly some errors in that content also, though Arduino does make an effort to fix these errors when they're reported.

The definitive reference will always be the datasheet, though those also have errors from time to time.

Just a heads up for anyone else who may be searching and has the same questions I did...

NO, The DS1302 is NOT I2C.

The easiest (IMO) ready-to-use library that requires no other dependencies or libs is this:

The above library is a no-bull**** that handles the basics in a very simple manner.

Additional reference (READ BEFORE USING!!!)

The documentation is sparse but mostly complete. The part that was not really explained on the above web site (or code samples) is the setDS1302Time(00, 55, 00, 2, 1, 04, 2018) function. They explained:

Second | Minute | Hour | Day | Month | Year

Yet, the function takes 7 (SEVEN) arguments. The correct "definition" for this function SHOULD be:

Second | Minute | Hour | DayOfWeek | Date | Month | Year

The DayOfWeek should be 1-7 (Corresponding to Monday-Sunday). A particular note about this value to those who wonder.. It seems this value is simply stored and incremented every 24 hours (resetting to "1" after "7"). That said, it really does not matter if you wish to "start the week on Sunday" vs "start the week on Monday" - as that is really abstracted and the chip does not actually care what day each "number" represents. It simply tracks "day 1-7" and starts over.

Hooking this up?

You will need 3 digital pins. One for "clk", one for "dat" and one for "rst". Again, it is NOT I2C. Follow the rest of the guidelines on the site above and you should have a working RTC.

Hope this helps someone :slight_smile:

deanrantala:
Currently, I am attempting to use it w/ the Time.h library (which is, itself not very clear) and cannot figure out how to even set the time from a unix timestamp.

Do you mean, set the DS1302 from a Unix timestamp?
Or set the Time library time from a Unix timestamp?