Reply to topic  [ 35 posts ]  Go to page 1, 2, 3, 4  Next
DS1302 Real Time Clock Module (HCMODU0035) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 669
Post DS1302 Real Time Clock Module (HCMODU0035)
Image

Description:

The DS1302 trickle-charge timekeeping chip contains a real-time clock/calendar and 31 bytes of static RAM. It communicates with a microprocessor via a simple serial interface. The real-time clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or
12-hour format with an AM/PM indicator. Interfacing the DS1302 with a microprocessor is simplified by using synchronous serial communication. Only three
wires are required to communicate with the clock/RAM: CE, I/O (data line), and SCLK (serial clock). Data can be transferred to and from the clock/RAM 1 byte at a time or in a burst of up to 31 bytes. The DS1302 is designed to operate on very low power and retain data and clock information on less than 1μW. The DS1302 is the successor to the DS1202. In addition to the basic timekeeping functions of the DS1202, the DS1302 has the additional features of dual power pins for primary and backup power supplies, programmable trickle charger for VCC1, and seven additional bytes of scratchpad memory.

FEATURES
    ƒReal-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100
    ƒ31 x 8 Battery-Backed General-Purpose RAM
    ƒSerial I/O for Minimum Pin Count
    2.0V to 5.5V Full Operation
    Uses Less than 300nA at 2.0V
    Single-Byte or Multiple-Byte (Burst Mode)
    Data Transfer for Read or Write of Clock or RAM Data
    ƒSimple 3-Wire Interface
    TTL-Compatible (VCC = 5V)
    Optional Industrial Temperature Range: -40°C to +85°C
    ƒDS1202 Compatible


Arduino Example Sketch:

Code:
/* FILE:    ARD_1302_RTC_Example_Sketch_HCMODU0035
   DATE:    03/09/13
   VERSION: 0.1
   
REVISIONS:

20/09/13 Created version 0.1

This is an example of how to use the Hobby Components 1302 Real Time Clock
module (HCMODU0035). This example uses the RTC library written by Henning Karlsen
(http://www.henningkarlsen.com/electronics/). This example sketch demonstrates
how to read and write to the RTC module. To connect the module to your Arduino
please see the following pinout:

PINOUT:

MODULE    ARDUINO
GND       GND             
VCC       +5V             
SCK       D4
I/O       D3
RST(CS)   D2


You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used for the purpose of premoting or selling products
that directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER. */

/* Define the DIO pins used for the RTC module */
#define SCK_PIN 4
#define IO_PIN 3
#define RST_PIN 2

/* Include the DS1302 library */
#include <DS1302.h>

/* Initialise the DS1302 library */
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()
{
 
  /* Set the time and date to 16:30 on the 3rd of September 2013 */
  rtc.setDOW(MONDAY);
  rtc.setTime(16,30,0);
  rtc.setDate(3, 9, 2013);
 
  /* Read the time and date once every second */
  while(1)
  {
    Serial.print("It is ");
    Serial.print(rtc.getDOWStr());
    Serial.print(" ");
    Serial.print(rtc.getDateStr());
    Serial.print(" ");
    Serial.print("and the time is: ");
    Serial.println(rtc.getTimeStr());

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



Downloads:

Attachment:
DS1302.pdf

Arduino DS1302 RTC library written by Henning Karlsen (http://www.henningkarlsen.com/electronics/):
Attachment:
DS1302.rar


You do not have the required permissions to view the files attached to this post.


Sun Sep 08, 2013 10:23 am
Profile

Joined: Wed Nov 06, 2013 7:59 pm
Posts: 2
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
Hi,
how should I connect this RTC to Arduino Uno ?


Thu Nov 28, 2013 1:34 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 697
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
Connection to an Uno is as follows:

MODULE ARDUINO
GND -> GND
VCC -> +5V
SCK -> D4
I/O -> D3
RST(CS) -> D2

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Nov 29, 2013 11:21 am
Profile

Joined: Thu Dec 12, 2013 7:58 am
Posts: 35
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
can you advise how i connect this to my HCARDU0036 rev 3 mega AT2560-16AU please
i am having a problem finding pin 2, 3, and 4


Last edited by normski001 on Thu Dec 12, 2013 7:09 pm, edited 1 time in total.



Thu Dec 12, 2013 3:42 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 697
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
You should be able to connect it as per Uno pinout above

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Thu Dec 12, 2013 7:05 pm
Profile

Joined: Thu Dec 12, 2013 7:58 am
Posts: 35
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
andrew wrote:
You should be able to connect it as per Uno pinout above

i do not have d2, d3, d4 pins
here is my board
http://www.hobbycomponents.com/images/forum/ardunio_mega_pinout.jpg


Thu Dec 12, 2013 7:11 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 697
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
Ok I see the confusion D2, D3, & D4 refer to the digital pins that are just labeled 2,3, & 4 on your board where it says PWM

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Thu Dec 12, 2013 7:22 pm
Profile

Joined: Thu Dec 12, 2013 7:58 am
Posts: 35
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
i have just plugged the screen in them the outer holes 2 and 3 seem connected but not 4 on the display shield board
the 5v and gnd is also connected to outer holes on board.
the board and holes seem to be 2, 3, 11, 12, 13 pins connected to the empty display shield holes so no idea how i get to 4 for the rtc

on the lcd display i have D0 to D7 where i can putpins and d4 does go to the pin 4 you said, could i fix it there any advice would be help full please


Thu Dec 12, 2013 7:56 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 697
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
As you have a Mega would it be easier for you to use some of the other spare digital pins? Digital pins numbered 14 to 53 are not covered by the shield and so all you would need to do is change the pin assignment in the sketch. For example, in the example sketch in the first post find the following lines...

#define SCK_PIN 4
#define IO_PIN 3
#define RST_PIN 2

...and change the numbers to what ever digital pin numbers you use on your mega. Is this a solution or do you need to connect to the shield for some reason?

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Dec 13, 2013 11:23 am
Profile

Joined: Thu Dec 12, 2013 7:58 am
Posts: 35
Post Re: DS1302 Real Time Clock Module (HCMODU0035)
here is what i have done, gnd and +5v from top and bottom of digital pin block right of board, sck to pin 22 i/o to pin 24 rst to pin 26

Quote:
/* Define the DIO pins used for the RTC module */
#define SCK_PIN 22
#define IO_PIN 24
#define RST_PIN 26


when i load program above i get error
DS1302 rtc(RST_PIN, IO_PIN, SCK_PIN); this line goes yellow


below box goes orange and says DS1302 does not name a type
then lines in black box
sketch_dec13b:46: error: 'DS1302' does not name a type
sketch_dec13b.ino: in function 'void setup()':
sketch_dec13b:51: error: 'rtc' was not declared in the scope
sketch_dec13b.ino function 'void loop()':
sketch_dec13b:64: error: 'rtc' was not declared in the scope
sketch_dec13b:64: error:'MONDAY' was not declared in the scope


Fri Dec 13, 2013 1:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 35 posts ]  Go to page 1, 2, 3, 4  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD