Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: ttttkk on May 25, 2013, 06:48 pm

Title: DS1302 issue
Post by: ttttkk on May 25, 2013, 06:48 pm
Recently I bought a ds1302 module (see the pic below), after installed the library from http://www.henningkarlsen.com/electronics/library.php?id=5, the output of the clock is flawed.
The time and date are stored in the chip without problems, but It outputs like this if i give it 5v power from arduino. If powered by 3.3v, the time and date can't even store in the chip.

Monday 19.05.2012 -- 00:43:43
xxxxxxxxx 00.00.2000 -- 00:00:00
Monday 19.05.2012 -- 00:43:45
xxxxxxxxx 00.00.2000 -- 00:00:00
Monday 19.05.2012 -- 00:43:47
xxxxxxxxx 00.00.2000 -- 00:00:00
Monday 19.05.2012 -- 00:43:49
xxxxxxxxx 00.00.2000 -- 00:00:00

Code: [Select]
// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
 // Set the clock to run-mode, and disable the write protection
 rtc.halt(false);
 rtc.writeProtect(false);
 
 // Setup Serial connection
 Serial.begin(9600);

 // The following lines can be commented out to use the values already stored in the DS1302
 rtc.setDOW(SUNDAY);        // Set Day-of-Week to FRIDAY
 rtc.setTime(0, 43, 0);     // Set the time to 12:00:00 (24hr format)
 rtc.setDate(26, 5, 2013);   // Set the date to August 6th, 2010
}

void loop()
{
 // Send Day-of-Week
 Serial.print(rtc.getDOWStr());
 Serial.print(" ");
 
 // Send date
 Serial.print(rtc.getDateStr());
 Serial.print(" -- ");

 // Send time
 Serial.println(rtc.getTimeStr());
 
 // Wait one second before repeating :)
 delay (1000);
}

(http://www.hobbytronics.co.uk/image/cache/data/dealextreme/real-time-clock-ds1302-250x250.jpg)
Title: Re: DS1302 issue
Post by: Erdin on May 26, 2013, 12:09 pm
I'm not very fond of that code.
The DS1302 requires sometimes a very short delay, and I also doubt if interfacing the DS1302 is correct.

A voltage of 3.3V should be no problem.
A assume you use a 3.3V Arduino, so not only the power but also the digital pins of the Arduino are 3.3V. If you use for example a 5V Arduino Uno and power the RTC with 3.3V, that would not work.

On this forum, there are a number of problems with bad crystals. Some bad quality crystals seems to need 5V or else they won't work.
Title: Re: DS1302 issue
Post by: martindisenio on Aug 14, 2013, 03:18 am
I have the some module, but I don´t know how to connect this module with mi Arduino Demilanove 328
Can ´u helpme?
Title: Re: DS1302 issue
Post by: Erdin on Aug 14, 2013, 11:43 am
This has information about the wiring: http://playground.arduino.cc/Main/DS1302

When you need more help, we have to know so much more.
What kind of module do you have ? You could attach a photo of it.
The very cheap ones from Ebay have often problems with the crystal.
Do you use the newest Arduino software, version 1.0.5 ?
Title: Re: DS1302 issue
Post by: tprochazka on Mar 22, 2014, 06:07 pm
I have the same problem on the Arduino Uno, it is affected every even second. If I increase query speed fo 10x per second, 10 query are bad and next 10 OK. But if I use the same module and the same code on Arduino Nano R3, everythink is OK. Did you already solve the problem?
Title: Re: DS1302 issue
Post by: Zyklotrop on Aug 21, 2014, 10:16 am
I have the same RTC module as shown in the picture on top of the thread.
This ist how I wired it up after heaving read the DOCS:

Code: [Select]

Chip Pin        Arduino Pin          Module Pin
CE pin     -> Arduino Digital 2    (RST)
I/O pin    -> Arduino Digital 3    (DAT)
  SCLK pin  -> Arduino Digital 4    (CLK)
  VCC       -> Arduino 3.3V         (VCC)
  GND       -> Arduino GND          (GND)


This one works for me with the serial simple sketch of the henning karlsen library. Time can be stored and runs.
Didn't try how battery works yet.
If I connect VCC to 5V I get the same weird results as mentioned above. 3.3V works fine for me.
Title: Re: DS1302 issue
Post by: JimboZA on Aug 21, 2014, 10:25 am
I had a 1302 running on 5V with HK's library with no problems. It was a standalone loose chip with a loose xtal, hooked up on breadboard.

I say "had", because I leveled-up to a 1307 since I2C is more pin efficient.
Title: Re: DS1302 issue
Post by: Snejq on Apr 08, 2015, 03:20 pm
Try connecting i/o by the 1k resistor :)