New library: DS1302 (Real-time Clock)

Hi

I have made an easy-to-use library for the DS1302 RTC (Datasheet: http://datasheets.maxim-ic.com/en/ds/DS1302.pdf).

More infomation and download can be found here: Electronics - Henning Karlsen

Regards
Henning

V2.0 is now released.

You can now use the on-chip RAM. *All 31 bytes *:wink:

/Henning

Hello you!

Nice library. The code was easy to read and follow.
Some critique and questions:

I think you should use more constants and #defines (if you must) for making the code even more readable. Especially where you use numeric constants for indexing arrays and looping through them.

I see you often declare the return value at local scope of the function like this:

char* myfunc() { char* out = "test"; return test; }

This is fairly risky business. The out variable is actually out of scope after the myfunc returns, so it should be destroyed in memory. I'm sure this is not what you want.

A solution could be to force the user to provide the target string/buffer as an argument to the function: getDateStr(char* targetBuffer)

Morsomt å se flere nordmenn på forumet! Bor faktisk i Oslo selv. Studerer ved NITH.
Snakkes!

Thanks for your comments.

I usually don't program in C / C++, so this is quite new to me. I am more experienced in Visual Basic / PHP / ASP, and are using these libraries as a learning experience.

I will look into what you said as soon as I am back from vacation (leaving tomorrow morning).

On a sidenote: Alltid hyggelig med andre nordmenn :slight_smile:
Har du laget noe morsomt med Arduino, eller noen andre MCUer for den saks skyld?

/Henning

Hello i recetly downloaded the DS1302 and it worked fine with a commercial DS 1302 board having a capacitor to retain information when no power supply is coming from the boad .

:)However using the library i noticed than if i unplug the ds1302 and later put it back in service all the information previously charged is no longer present the DS 1302 starting 1/1/2000 at 0h .Is their a clue to charge the built in capacitor present with commercial DS1302 board

I am sorry, but I have never used a board with a capacitor instead of a battery. I see no reason to use a capacitor as long as a cheap CR2032 can keep the DS1302 running for 10+ years.

My guess is that the capacitor just is not large enough to keep the DS1302 supplied with power long enough. This is somthing you really should talk to the makers of the board about.

I can not see that there is anything my library can do about this.

/Henning

V2.1 is now released.

New: Ability to set the Trickle-Charge register so you can now use SuperCaps instead of batteries :slight_smile:

/Henning