Pages: [1]   Go Down
Author Topic: hard time to use a DS1302  (Read 2658 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi There,

I bought a DS1302 (see here : http://dx.com/p/ds1302-real-time-clock-module-with-battery-cr2032-126453 ).
I use this piece of code : http://playground.arduino.cc/Main/DS1302 (or also a library from here : https://github.com/msparks/arduino-ds1302/blob/master/DS1302.h).

However, I am getting wierd result.
The time I see is not one the one I read afterwards.
When setting time for exemple, it affects the date...

Here below my sketch.

Anyone has ideas?

I get this as output : "08:17:09 21.09.2001 Sun" whereas my code sets :   rtc.setDOW(SATURDAY);   rtc.setTime(16, 1, 3);    rtc.setDate(7, 9, 13);  

Thanks,
Erwan

Code:
// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
//
// I assume you know how to connect the DS1302 and LCD.
// DS1302:  CE pin    -> Arduino Digital 12
//          I/O pin   -> Arduino Digital 11
//          SCLK pin  -> Arduino Digital 10
// LCD:     DB7       -> Arduino Digital 7
//          DB6       -> Arduino Digital 6
//          DB5       -> Arduino Digital 5
//          DB4       -> Arduino Digital 4
//          E         -> Arduino Digital 8
//          RS        -> Arduino Digital 9

#include <LiquidCrystal.h>
#include <DS1302.h>

// Init the DS1302
//DS1302(ce, data, clock);
DS1302 rtc(12,11,10);

// Init the LCD
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

void set_time() {
  rtc.setDOW(SATURDAY);    //
  rtc.setTime(16, 1, 3);     //
  rtc.setDate(7, 9, 13);   //
}

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
  //rtc.setTCR(TCR_OFF);
  // Setup LCD to 16x2 characters
  lcd.begin(16, 2);
  
set_time();

  // The following lines can be commented out to use the values already stored in the DS1302

}

void loop()
{
  // Display time centered on the upper line
  lcd.setCursor(4, 0);
  lcd.print(rtc.getTimeStr());
  
  // Display abbreviated Day-of-Week in the lower left corner
  lcd.setCursor(0, 1);
  lcd.print(rtc.getDOWStr(FORMAT_SHORT));
  
  // Display date in the lower right corner
  lcd.setCursor(6, 1);
  lcd.print(rtc.getDateStr());

  // Wait one second before repeating :)
  delay (1000);
}

* DS1302.h (3.22 KB - downloaded 180 times.)
* DS1302.cpp (9.94 KB - downloaded 158 times.)
* DS1302.pdf (55.92 KB - downloaded 192 times.)
« Last Edit: January 12, 2013, 02:39:21 pm by erwanl » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

fixed it...
seems I need to unplug VCC (the module then works on battery) when setting the time.

dont understand why. found it by luck smiley

anyway, now works !

/erwan
Logged

Global Moderator
Italy
Offline Offline
Brattain Member
*****
Karma: 328
Posts: 22747
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@erwanl:
this is the italian sub-section of the forum  smiley-wink
We (mostly) understand english but it's not the default language to use here  smiley-wink
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops sorry smiley
Can this topic be moved to the right place?

I'll pay more attention next time,

Grazie mille !
Logged

Global Moderator
Italy
Offline Offline
Brattain Member
*****
Karma: 328
Posts: 22747
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops sorry smiley
Can this topic be moved to the right place?
Hope a mod will do the job  smiley-wink

Quote
I'll pay more attention next time,

Grazie mille !
Ciao  smiley-grin
Logged


Pages: [1]   Go Up
Jump to: