How to: wire the DS1337 RTC?

I plan to use this RTC DS1337 to have alarms in my project in order to send the arduino to sleep and wake up it to measure different sensors, store the data and go to sleep again.

Here is the datasheet: http://datasheets.maxim-ic.com/en/ds/DS1337-DS1337C.pdf

I have a couple of doubts about how to wire it to arduino. I see the scheme in page 1, with pull-ups in INTA, SQW/INTB and SCL and SDA.

I plan to connect the RTC to a Li 3V CR2032 battery and not to the arduino's power pins, in order to save the date in the RTC, also when i don´t use the circuit with arduino.

So my first question is: Do i still need pull-up resistances in those four pins? Which one? 10K may be?

My other question is related to the use of INTA and SQW/INTB pins. Should i connect both to the arduino's pins 2 and 3? I need only one of them? I googled it but with not clear results about how to correctly wire this RTC.

So, all your idea will be really welcome!

Cheers,

Edited: Sorry, one more question. I saw in the next device, a capacitor near the DS1337, so, is it necessary? It does not appear on the datasheet scheme...

http://wiblocks.luciani.org/PICO/PICO1TRC-index.html

Ok, i reply partially to myself.

about the INTA and SQW/INTB pins, the datasheet say:

INTA: Interrupt Output. When enabled, INTA is asserted low when the time/day/date matches the values set in the alarm registers. This pin is an open-drain output and requires an external pullup resistor.

SQW/INTB: Square-Wave/Interrupt Output. Programmable square-wave or interrupt output signal. It is an open-drain output and requires an external pullup resistor.

It is the same with SCL and SDA. The dataheet said that the pull-up resistances are necessary. So i understand that the pull-up resistances are even required independtly of the power (3V, 3.3V or 5V). So the remaining question is: what resistance i should use with a 3V battery? 10K, 2.2K,...? Thanks!

I used an DS1337 with an Arduino. There are some minor issues you need to be aware, read my posting: http://timewitharduino.blogspot.com/2010/03/wiseduino-with-ds1337.html 10k for pull-ups are fine.

It is usually a good idea to have the capacitor on the power supply line. Since the DS1337 is low current and usually communicates at low frequency you could probably get away without it. Don't forget that sometimes the datasheets do not show all the components necessary to use a particular device (especially parts like decoupling capacitors).

The value of the pullup depends on your system voltage, the number of I2C devices on the bus and the frequency of the bus. In the PICO1TRC datasheet (which you have a link to) there is a table that shows you how to calculate the proper value. Typically a value between 4.7K and 10K works well.

(* jcl *)


www: http://www.wiblocks.com twitter: http://twitter.com/wiblocks blog: http://luciani.org

Hi!

Thanks for you ideas!

@jluciani and @ florinc: Now I wired a 0.1uF capacitor, following your recommendations, as well as 10K ohms resistances for the pull-ups.

On the other hand, i was testing if use a battery, the power from the arduino board, or both. Since i want to keep the time/date in the memory, i will use a battery, but.. alone? or together with the power from arduino? So, i wired the battery (Li 3V, CR2032) to the RTC, and it maintains the memory, but does not show the date in the serial. For that reason i wired both battery and arduino power by the use of two diodes since the RTC does not have an specific connection for power from the battery:

Arduino 5V/3V3 ---- Diode ---- RTC Vcc Battery -------------- Diode ----R TC Vcc

And it runs: remains the data in the memory and shows results in serial.

However, if i disconnect the power from arduino, remaining together GND from the battery and the arduino... it still shows the time/date in the serial! Why happends that?

Now my questions are related to outputs from the RTC...

If i want to send the arduino to sleep and get it up onces per hour to measure at different sensors... is it enough to use the INTA out? or i should use both INTA + INTB/SQW?

On the other hand, i was testing different codes and libraries without results... white screens in the serial... not setting the time and date in the RTC... and so on.

I tested the RTC by using the DS1307 library, and it runs perfectly. The time and date settings works, and it shows the time and date in the serial... I will follow trying to take it running with a DS1337 library or code. BTW, anybody have a simple code to test this RTC? i mean just only setting, showing data in the serial, establishing alarms,..

Thanks!

I am not sure if this post should go to the Software section of the forum, but since it is related to the topic that i have on hand about wiring the DS1337, i put it here.

About the code to run the DS1337,

I have the library and example code posted here:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191209057/15

I saved the library into a "ds1337" folder under "libraries" into the "hardware" folder of Arduino IDE.

I tried to compile, but i had all these error:

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\/ds1337.h:10:20: error: global.h: No such file or directory

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\/ds1337.h:292: error: 'boolean' has not been declared

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\/ds1337.h:318: error: 'boolean' has not been declared

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:9: error: 'PROGMEM' does not name a type

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In constructor 'DS1337::DS1337()':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:24: error: 'alarmId' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'int8_t DS1337::Init()':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:64: error: 'delay' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:69: error: 'B10000000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:74: error: 'B01101000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'void DS1337::writeRegister(uint8_t, uint8_t)':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:92: error: 'B01101000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'uint8_t DS1337::getRegister(uint8_t)':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:104: error: 'B01101000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'void DS1337::clockStart()':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:118: error: 'B10000000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:121: error: 'B00000000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'void DS1337::clockRead()':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:128: error: 'B01101000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'void DS1337::clockSave()':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:147: error: 'B10000000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:149: error: 'B01101000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: At global scope:

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:173: error: 'boolean' has not been declared

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'uint16_t DS1337::clockGet(uint8_t, int)':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:181: error: 'B01110000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:187: error: 'B00110000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:190: error: 'B00000111' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:196: error: 'B00010000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:196: error: 'B10000000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:199: error: 'B11110000' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'uint8_t DS1337::bcdToBin(uint8_t, uint8_t)':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:465: error: 'B00001111' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp: In member function 'void DS1337::printRegisters()':

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:688: error: 'SPrint' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:689: error: 'Serial' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:689: error: 'HEX' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:691: error: 'BIN' was not declared in this scope

C:\Archivos de programa\arduino-0017\hardware\libraries\ds1337\ds1337.cpp:694: error: 'delay' was not declared in this scope

I work with Arduino 017 under Windows XP.

Any idea f i am doing something wrong or if the problem is in the library?

Thanks!

I saved the library into a "ds1337" folder under "libraries" into the "hardware" folder of Arduino IDE.

Wrong place.

It goes in the libraries folder along with where you sketches are normally stored.

Hi Grumphy_Mike,

Thanks for your comment.

I have all my libraries here:

C:\Program Files\arduino-0017\hardware\libraries\

and i never had problems with them (except small silly problems due to case sensitive names).

I checked the code from the *.cpp and *.h files, and i find a problem: When the libraries are called, includes expressions such as...

"#include ".../ds1337.h"

just only by removing ".../" characters, the libraries are located by arduino IDE without problems now. But the list of errors remains.

BUT glooging a little bit i saw this link: http://code.google.com/p/wiseclock2/downloads/detail?name=watch.zip&can=2&q=

It has a new version of the library, that compiles form me without problems!!! :D

I take a fast look to the code of new *.cpp and *.h files, and for the moment they call in a different way to the libraries, so may be this resolve the problem.. I don´t know.

In any case, it seems to be the same library but modified in some way. So since the examples complies without problems, i will try this evening to run it into Arduino (i don´t have it here now...), and post here the news.

Thanks!

madepablo, As mentioned in my posting (http://timewitharduino.blogspot.com/2010/03/wiseduino-with-ds1337.html), I had similar problems compiling the existing libraries. (One issue, for example, was references to a different (than the standard ones coming with Arduino IDE) set of twi files (they handle the i2c communication), provided with jluciani's library.) Keep in mind that the ds1337 library I posted does not have the alarm/interrupt functionality implemented yet. I did not even try to include it (because of laziness). But the related functions (dealing with alarm, interrupts etc) should be copied and adapted from the 2 previous libraries. Please feel free to add these functions, I would be glad to include them (I actually need them) in my watch software.

As mentioned in my posting (http://timewitharduino.blogspot.com/2010/03/wiseduino-with-ds1337.html), I had similar problems compiling the existing libraries. (One issue, for example, was references to a different (than the standard ones coming with Arduino IDE) set of twi files (they handle the i2c communication), provided with jluciani's library.)

Since I had used the Atmel TWI library on a different job (and I knew the code) I decided to use it for the RTC library and sketches. The primary changes to the code was the addition of the doxygen documentation.

I believe I have almost all of the functions of the DS1337 implemented. The one thing I will be adding is epoch time conversions.

(* jcl *)

Thanks,

@florinc: Yes, i saw your problems... and i also tried it... with your same results...

@Jluciani: thanks for sharing your codes! Could you also show as a running example code? I don´t have clear if i am not connecting things correctly or if there is a problem of code, such for florinc. Thanks!

I will go ahead to test the last library that i downloaded to see if i could have it running also with alarms and interrupts. Thanks!!

RTC Interrupt example that prints the time when the alarm goes off --- http://wiblocks.luciani.org/docs/app-notes/pico1trc-rtc.html

RTC interrupt example that writes a block of data to a uSD card when the alarm goes off --- http://wiblocks.luciani.org/docs/app-notes/nb2as-uSD.html

RTC example that periodically reads and prints the time -- http://wiblocks.luciani.org/docs/app-notes/nb1a-rtc.html

(* jcl *)


www: http://www.wiblocks.com twitter: http://twitter.com/wiblocks blog: http://luciani.org

Thanks jluciani for haring your code. I will try it also, and post here the results.

Cheers,

I am back trying to run the DS1337 triggering alarms.

For the moment the time and date is ok, but the day of the week runs bad. It even return to me day 6… i don´t know where is the problem in the library…

On the other hand, i am not lucky with the alarms. They still don´t work…

News coming soon…

I am back trying to have the alarms running...

in the mean time, i saw this library developed for a module with an RTC ds1337 and other components (seems a RAM memory, but i am not sure).

http://swfltek.com/store/framshield.html

In any case, i tried it, and it runs, and also trigger alarms!!

However, the library it is a little bit confuse because i would like to remove all the function not related to the RTC. On the other hand, the clock and alarm setting is not as friendly such as in other libraries, and you can not manage all the options of the alarms that provide the ds1337 chip.

So, for the moment i will be back to the other libraries that i am testing and try to solve the problem of setting and trigger the alarms.

News coming soon..

I found a problem at D1337 library. This is the first error returned by Arduino IDE during complilation process:

C:\Archivos de programa\arduino-0017\hardware\libraries\DS1337\/DS1337.h:251: error: expected unqualified-id before 'void'
volatile static voidFuncPtr DS1337callbackFunc[3];

what is the line 251.

I tried including previously this line:

typedef void (*voidFuncPtr)(void);

but it neither work, producing the same error....

Any idea?

Here i posted the DS1337 RTC wiring diagram that i use: http://fritzing.org/projects/ds1337/

Due to the limitations in components in frizting, take into account: * the 555 is in really our DS1337 * the crystal must be a 32.728 kHz * the resistances are 10kOhms * the capacitor is a 0.1 uF

I don´t use the INTB/SQW out, but i draw its connection just in case it could be useful to you.

If you just want to setup the clock and get the time and date, you could use the DS1307 library from this from. But if you want to use the alarms, you need any of the DS1337 libraries presented in this forum and also here in this post.

For the moment i have a lot of problems to have the alarms working, but this is another story.

limitations in components in frizting

No, you can easily change that all...

Thanks deSilva!

yes, you are right!. I know that everybody can develop their own componentes. But for the moment, this is the first time that i use Fritzing, and at present day there is not that component on the default library. In the future, if i learn how to do it, and i have time, i will try to develop and share it.

Thanks again for your comment!

is the INTB/SQW for the alarm? if i want to skip it, what pins do i not use then?