DS1302 RTC problems

Hi I have the DS1302 working but my problem is the layout in serial monitor looks like this

Time = 21:26:21, Date(day of month) = 6, Month = 10, Day(day of week) = 7, Year = 2013 Time = 21:26:26, Date(day of month) = 6, Month = 10, Day(day of week) = 7, Year = 2013 Time = 21:26:31, Date(day of month) = 6, Month = 10, Day(day of week) = 7, Year = 2013

I would like it to look like this

Time = 21:26:31, Sunday 6th October 2013 Is this possible? Below is the code I am using its pretty big and if anybody has a smaller one that does my required format that would be amazing Thanks in advance Ok the code is to long to upload its from the arduino playground here is the link []http://playground.arduino.cc/Main/DS1302]](http://playground.arduino.cc/Main/DS1302)

HI I am using the DS1302 RTC I have got it to work using the skect link below

http://playground.arduino.cc/Main/DS1302 the the serial looks like this

Time = 10:08:00, Date(day of month) = 15, Month = 4, Day(day of week) = 2, Year = 2013 Time = 10:08:05, Date(day of month) = 15, Month = 4, Day(day of week) = 2, Year = 2013 Time = 10:08:11, Date(day of month) = 15, Month = 4, Day(day of week) = 2, Year = 2013

i would like it to look like this in my serial monitor

Time = 10:08:11, 6th October 2013

is this possible?

Is this possible?

Of course.

Below is the code

No, it isn't. Below is a mangled attempt at a link.

Ok the code is to long to upload its from the arduino playground here is the link

http://playground.arduino.cc/Main/DS1302

if you can help that would be appreciated if your looking for somewhere to just be ad hominem then i sugest you try facebook its full of people like that

You just made my list. Congratulations.

Looks like all the data is printed here:

  sprintf( buffer, "Time = %02d:%02d:%02d, ", \
    bcd2bin( rtc.h24.Hour10, rtc.h24.Hour), \
    bcd2bin( rtc.Minutes10, rtc.Minutes), \
    bcd2bin( rtc.Seconds10, rtc.Seconds));
  Serial.print(buffer);

  sprintf(buffer, "Date(day of month) = %d, Month = %d, " \
    "Day(day of week) = %d, Year = %d", \
    bcd2bin( rtc.Date10, rtc.Date), \
    bcd2bin( rtc.Month10, rtc.Month), \
    rtc.Day, \
    2000 + bcd2bin( rtc.Year10, rtc.Year));
  Serial.println( buffer);

Change the formatting some, and add an array to from day of the week as a number to the Name of the day: dayArray[] = {"None","Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday","Sunday",}; assuming the days come back as 1-7, and 0 is not used.

Thanks for the reply but i am new to this its my 1st project and i don't really understand what you mean sorry for my lack of knowledge

Ok, go explore the learning section and learn how the Serial.print() and Serial.println() statements work as a starting point.

OK I cracked it 1st i changed the vcc2 pin from 5v to ground this stopped the corruption in the serial data

then swapped the serial line

its basic small & works

#define SCK_PIN 6
#define IO_PIN 7
#define RST_PIN 8


#include <DS1302.h>


DS1302 rtc(RST_PIN, IO_PIN, SCK_PIN);

void setup()
{
  /* Clear the 1302's halt flag */
  rtc.halt(false);
  /* And disable write protection */
  rtc.writeProtect(false);
 
  /* Initialise the serial port */
  Serial.begin(9600);
}

/* Main program */
void loop()
{
  
 
  rtc.setDOW(MONDAY);
  rtc.setTime(02,29,0);
  rtc.setDate(7, 10, 2013); 

  while(1)
  {
    Serial.print(" ");
    Serial.print(rtc.getDOWStr());
    Serial.print(" ");
    Serial.println(rtc.getDateStr());
    Serial.print(" ");
    Serial.print("Time: ");
    Serial.println(rtc.getTimeStr());

    /* Wait before reading again */
    delay (5000);
  }
}

What corruption? You hadn't mentioned that.

"Primary Power-Supply Pin in Dual Supply Configuration. VCC1 is connected to a backup source to maintain the time and date in the absence of primary power. The DS1302 operates from the larger of VCC1 or VCC2. When VCC2 is greater than VCC1 + 0.2V, VCC2 powers the DS1302. When VCC2 is less than VCC1, VCC1 powers the DS1302. "

So you'll be running on battery power only until it discharges I guess.

sorry i should have put the corruption in the new smaller code i tried so when i plug the vcc2 into + it turns out the data below if i put vcc2 into - it runs normally what could be causing this ?

serial example when vcc2 is in +

Monday 07.10.2013 Time: 02:29:01 xxxxxxxxx 03.08.2009 Time: 01:14:03 Monday 07.10.2013 Time: 02:29:11 xxxxxxxxx 03.08.2009 Time: 01:14:11 Monday 07.10.2013

Time: 02:29:21

serial example when vcc2 is in -

Monday 07.10.2013 Time: 02:29:00 Monday 07.10.2013 Time: 02:29:05 Monday 07.10.2013 Time: 02:29:10 Monday 07.10.2013

Time: 02:29:15

Wow, that is weird. Can only guess the power supply is not very good.

Just note that in my experience the DS1302 is not a particularly reliable time keeper and can vary in accuracy allot on a per DS1302 chip basis.

Would suggest using it in conjunction with network time keeping every 6 hours or so

@johnsmith23: Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator

so it seems that the ds1302 and ds1307 are both fault ridden , is there any other rtc that is reliable ?

johnsmith23: so it seems that the ds1302 and ds1307 are both fault ridden , is there any other rtc that is reliable ?

What do you mean, fault ridden? Are you saying it has a gradual error? Well you get what you pay for, you can get clock chips that are temperature compensated.

http://www.adafruit.com/products/255

johnsmith23: so it seems that the ds1302 and ds1307 are both fault ridden , is there any other rtc that is reliable ?

I tested a bunch of DS1307 chips for many weeks back when the time library was created and never saw a fault. If you haven’t already, try one on well-made breakout board before ruling out this chip.


Mod – It looks like this RTC discussion is hardware related rather than anything directly to do with the time library. I think the posters issues would be apparent using any test harness for the RTC chips. If there is further discussion on RTC chips, it may be better to put this back in its own thread and add a link here to that, to keep this thread focused on the Time library .

Michael Margolis

Hi, I've used a few DS1307's and found them to be just fine. A CR2032 or even a tiny CR1225 keeps the time going during power down, etc. There is a DS32kHz IC/Module this is a temperture compensated OSC, running at 32.768Khz and can be used to replace the 32.768Khz crystal and give high accuracy, but this too needs battery backup. Maxim now own Dallas, who first produced these IC's.

Hope it helps.

Regards

Mel.