Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Real time clock DS1307 time keeping registers

Status
Not open for further replies.

jay_3189

Banned
Full Member level 1
Joined
Sep 19, 2013
Messages
104
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Location
Ahmedabad
Visit site
Activity points
0
hello

could any one explain me DS1307 Time keeping Resistor...

0X00h resistor has three bit fro Bit4 to 6 has written 10 Seconds.
what is that and why to set that?
same In 0X 01h resistor.


in next following resistor for 24hour selection bit 5 has 10hour written. what is that..? Time-Keeper-Registers.png
 

Hi jay_3189,
Bit4 to bit6 represents the tens place of the value and bit0 to bit 3 represents the ones place of the value. For example, to set a value of 34, write 0x03 to bits4 to 6 and write 0x04 to bits0 to 3.



Regards,
Raj Gunaseelan

- - - Updated - - -

In register 0x02, bit6 is used to select the hour format: 1 to 12 am/pm (or) 0 to 23 hour format. If 1 to 12 am/pm format is selected, bit 5 gives am or pm, bit4 gives the tens value of hour, bits3 to 0 give the ones value of hour. If 0 to 23 hour format is selected, bits5 to 4 give the tens value of hour, bit3 to 0 give ones value of hour.

Regards,
Raj Gunaseelan
 
Hi jay_3189,
Bit4 to bit6 represents the tens place of the value and bit0 to bit 3 represents the ones place of the value. For example, to set a value of 34, write 0x03 to bits4 to 6 and write 0x04 to bits0 to 3.



Regards,
Raj Gunaseelan

- - - Updated - - -

In register 0x02, bit6 is used to select the hour format: 1 to 12 am/pm (or) 0 to 23 hour format. If 1 to 12 am/pm format is selected, bit 5 gives am or pm, bit4 gives the tens value of hour, bits3 to 0 give the ones value of hour. If 0 to 23 hour format is selected, bits5 to 4 give the tens value of hour, bit3 to 0 give ones value of hour.

Regards,
Raj Gunaseelan


Thanks for your valuable replay..
now I am getting some clearer idea about this but still with few doubts.

So, now if I want to set the hour or second whatever then, does I write values in hexadecimal only or in other format?
(as datasheet saying resistors have BCD value)
and how could I read? I mean when I read particular resistor then how I comes to know the exact time. is that need any kind of conversion?
 

as datasheet saying resistors have BCD value

Yes, BCD format is what I explained.

does I write values in hexadecimal only or in other format?

No. hexadecimal is different from BCD. For example, a decimal value of 65 is represented in hexadecimal as 0x41, whereas for the RTC register you need to split 65 as 0x06(tens place) and 0x05(ones place). BCD is nothing but Binary Coded Decimal.

For reading, assume setting is for 24hour format, if register 0x02 reads a value 00100011, (00)10 gives 2(tens) and 0011 gives 3(ones). Therefore, the hour is 23.


Regards,
Raj Gunaseelan
 
Last edited:

Yes, BCD format is what I explained.



No. hexadecimal is different from BCD. For example, a decimal value of 65 is represented in hexadecimal as 0x41, whereas for the RTC register you need to split 65 as 0x06(tens place) and 0x05(ones place). BCD is nothing but Binary Coded Decimal.

For reading, assume setting is for 24hour format, if register 0x02 reads a value 00100011, (00)10 gives 2(tens) and 0011 gives 3(ones). Therefore, the hour is 23.


Regards,
Raj Gunaseelan

ok I get it clearly now.
but what for year? I mean if I want to set year 1989 then how could I?

and how could I read value?
I mean if I call resistor address then it won't get date , year or anything directly in in decimal?
 

Year 1989
You can set only 00 to 99
19 set in manually in the source code
 
and how could I read value?
I mean if I call resistor address then it won't get date , year or anything directly in in decimal?

No you cannot read direct decimal. suppose you set the year as 99. You do this by writing 0x09(tens) and 0x09(ones). While reading the same register, you get 153 decimal which is 99 in BCD. So, you have to decode 153 as 99 through code as shown below:
Code:
decimal = (((153 & 0xF0) >> 4) * 10) + (153 & 0x0F )

Regards,
Raj Gunaseelan
 
No you cannot read direct decimal. suppose you set the year as 99. You do this by writing 0x09(tens) and 0x09(ones). While reading the same register, you get 153 decimal which is 99 in BCD. So, you have to decode 153 as 99 through code as shown below:
Code:
decimal = (((153 & 0xF0) >> 4) * 10) + (153 & 0x0F )

Regards,
Raj Gunaseelan

Thanks a lot....
 

Year 1989
You can set only 00 to 99
19 set in manually in the source code

There is no "19", the year settings refer to 2000 - 2099 and the programmed leap years are for 2000-2099, not 1900-1999
 
I have also read the RTC , and clear (0h - CH<7>) bit and i am getting output like date is 00-01 - 00 (DD - mm -yy) and time like starting from 00 : 01:02 i.e it is increasing
i.e RTC is Working
But Now the Problem is I want to set the date and time like its 10th feb,14 today so I have written a function
Code:
void write_ds1307(unsigned short address,unsigned short w_data)
{
i2c_Start();         // issue I2C start signal
i2c_Write(0xD0);        // send byte via I2C (device address + W)
i2c_Write(address);     // send byte (address of DS1307 location)
i2c_Write(w_data);      // send data (data to be written)
i2c_Stop();          // issue I2C stop signal
}
but using this how can i write /SET time , date

Like I have gone through the post also

it's BCD conversion like '13' is just like 1(0001) & 3 (0011)

I am not getting properly help me out of this !!
 

ya It's done but one problem is there still

The second stamp is running quickly in comparison to REAL TIME SCENARIO
so the minute id updating quickly like every minute is like CHANGING for 27 seconds only
rather than 60 secs, I checked the Output i.e coming via RTC and compared that with Stop Watch then I found that seconds Interval is increasing QUICKLY ,

Any Advice ??
 

ya It's done but one problem is there still

You mean without overflowing seconds the minute is updating?

The second stamp is running quickly in comparison to REAL TIME SCENARIO

change the another crystal 32768KHz

Some time it may occurs with your source code and with out checking source code we can not guess

- - - Updated - - -

There is no "19", the year settings refer to 2000 - 2099 and the programmed leap years are for 2000-2099, not 1900-1999

Dear Alex Thanks for advice

Actually what happen if we set it to increment from 1900 to 1999 since the device increment from 00-99 and in both case we have to set thousand digit manually in the source code


Just only understand purpose
 
Last edited:
  • Like
Reactions: embRTS

    embRTS

    Points: 2
    Helpful Answer Positive Rating
Check The two capacitors that connected to the clock Crystal or change the another crystal 32768KHz

There are no capacitors (and if there are it is wrong), the device needs just a crystal connected between X1-X2 pins but as close as possible


Actually what happen if we set it to increment from 1900 to 1999

I believe you'll get wrong results for leap years because the datsheet says

FEATURES:
ƒ Real-Time Clock (RTC) Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the week, and Year with Leap-Year Compensation Valid Up to 2100

and since there is no way to distinguish between 19xx and 20xx and there are only 100 possible year values 00-99, they represent 20xx
 

Ya I agree with you
I have read the Application Notes 58 for RTC there also it is mentioned about that only,
I am trying to debug the Scene !!
 

There are no capacitors (and if there are it is wrong), the device needs just a crystal connected between X1-X2 pins but as close as possible

I also noticed that the datasheet is not showing external capacitor connected to X1 and X2 pins

as well as I faced same problem in the my actual hardware that RTC working 11 seconds lead than the actual time about seven days. Therefore I connected two capacitors and I observed the efferent, but I am not trying to say time is accurate
 

Yes I agreed and I removed wrong commence from my post #13

However I further observed this from the Application Note 58

CRYSTAL PARAMETERS
Crystals have several fundamental characteristics that are important to the design of an oscillator circuit.
Figure 3 shows the equivalent circuit for a crystal. Near the resonate frequency the circuit consists of a
series circuit including motional inductance L1, motional resistance R1, and motional capacitance C1. The
parallel component CO is the shunt capacitance of the crystal.

Fast Clocks
The following are the most common scenarios that cause a crystal-based RTC to run fast.
1) Noise coupling into the crystal from adjacent signals. This problem has been extensively covered
above. Noise coupling usually causes an RTC to be grossly inaccurate.
2) Wrong crystal. An RTC typically runs fast if a crystal with a specified load capacitance (CL) greater
than the RTC-specified load capacitance is used. The severity of the inaccuracy is dependent on the
value of the CL. For example, using a crystal with a CL of 12pF
 
Last edited:

Hey Guys,

I want to interface DS1307 RTC with 8051 base microcontroller.

My question is how to set time and date in RTC register when IC is initialize?

I know that for setting time i have to send BCD code to RTC but i am not properly clear.

and in more for upper nibble & lower nibble i have to send data?
 

@ Jignesh you have to set suppose hour or Date then first try with changing in the Minute stamp which is change by writing Value to the "1h"address like you have to start i2c communication then address of DS1307 then Register Address (like Minute - 1h OR hour - 2h) then write the value of the minute or hour then Stop the i2c Communication

- - - Updated - - -

@PA3040 :: ya I also got the same analysis from application notes first watch the Layout of which ALEX also mentioned and another is the Crystal Value relation with the Load Capacitor,

Now my question is that if we do not give Power 5V to DS1307 but a battery is connected then will it run with Battery Power only

Because I tested that REMOVING the Power source I am getting the Output like "????" so It is not working with Battery Power but as soon as I power it up it shows the time and Date InCREASINg
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top