Using a DS1302 clock module

http://www.ebay.com.au/itm/181114663324?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

I have one of these and trying to figure out how to use it.

I have the DS1302 library from here: Arduino Playground - HomePage.

And an example that just sets the time on the chip and then reads it and outputs it in the serial monitor window.

The library seems to successfully read the time from the chip but it doesn't set it successfully. It seems to be set at some default value from the time of manufacture perhaps.

Has this problem been encountered previously and covered? If so what is the solution?

I use a 1302 on my Arduino webserver.

I have 2 sketches: one simply sets the time. I hardcoded the time into the sketch, a few minutes ahead. Then I compile and upload, which of course sets the time fast and I view that in monitor. I watch the clock on my pc, and restart the monitor at the appropriate time which resets the sketch and sets the correct time. The sketch then sets the rtc to read only.

Then in my other sketch, the "real" one, I only read the time. You can see my time as published by my Arduino web server here, although our ADSL is a bit dodgy in the storms we've been having.

I use the library of Henning Karlsen.

I had a similar problem with my cheap import RTC. In order to set the time, I had to use this:

This one may also work to set the time:

Thanks folks.

I will try them out until I find one that works with my device.

Well I have tried several libraries and bits of code and nothing works with my DS1302.

And I have found numerous pieces of advice stating that they are difficult to deal with.

In short they are crap and I think it is time to bin it and get a better RTC that uses standard communication protocols.

It is just not worth the aggravation.

boylesg:
I think it is time to bin it and get a better RTC that uses standard communication protocols.

In that case may I suggest the DS3231 instead of the DS1307. The DS3231 is more accurate (less drift).

boylesg:
If so what is the solution?

Look at this: Ways to update the RTC DS3231 from NTP server (the code is compatible with a wide range of RTC chips DSxxxx). The source code does not use RTC library. The program communicates directly with the RTC chip. It is very easy to take the part, adapt and use (see set_rtc_datum and set_rtc_time).