| Author |
Message |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
31 Jan 2008 13:13 RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
hello all..
i want to make the alarm using DS1307 and MCU 89S52.
and with the help of alarm i want to turn on/off the LEDs.
i have made routines for LCD 8-bit mode, 4X4 matrix Keyboard.
now what should i take next step for implementing clock and display it on LCD..??
can any one please help me..
All suggestions will be appriciated.
Thanks to you all in advance...
PS:: i am using Assembly Language language..
Last edited by H_D_R on 07 Mar 2008 13:13; edited 2 times in total |
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
04 Feb 2008 9:50 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
i am able to understand the I2C routines for RTC but still i am confused for implementation of clock.
can any one help me please..
i have read some of threads regarding RTC but still not much clear...!!?
by the way what is watchdog timer.
can i use it in my application...???
Last edited by H_D_R on 04 Feb 2008 11:19; edited 1 time in total |
|
| Back to top |
|
 |
Ceko_Boy
Joined: 04 Feb 2008 Posts: 2 Helped: 1
|
04 Feb 2008 11:05 RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Because I don't understand ASM language, so I tell you about watchdog.
Watchdog timer is a timer that sends out a pulse every consecutive time. the delay can be preset or determined by user.
Microcontroller will or device that sent this pulse notifies another device that "I'm alive and ok!". Eg, a device receive a watchdog pulse from a microcontroller every 1s. When the device didn't receive it, it sends out reset signal to the microcontroller. In this way, the system will never hang.
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
04 Feb 2008 11:16 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| Ceko_Boy wrote: |
Because I don't understand ASM language, so I tell you about watchdog.
Watchdog timer is a timer that sends out a pulse every consecutive time. the delay can be preset or determined by user.
Microcontroller will or device that sent this pulse notifies another device that "I'm alive and ok!". Eg, a device receive a watchdog pulse from a microcontroller every 1s. When the device didn't receive it, it sends out reset signal to the microcontroller. In this way, the system will never hang. |
Thank you..
i am using asm means assembly language.
hope so any body else can help.
anyway thank u.
|
|
| Back to top |
|
 |
laktronics
Joined: 06 Jan 2007 Posts: 793 Helped: 134
|
04 Feb 2008 11:57 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Hi,
A small correction regarding Watchdog Timer. It is a timer which has to be constantly triggered by the microcontroller at regular intervals to prevent it from producing an output pulse. If the controller fails to do it due its program losing control for some reason, the pulse output from the watchdog is used to reset the micro, thus ensuring that the micro recovers from its hanging state. It is a circuit that works like a watchdog on the proper working of the micro. You may or not, use it in your application.
Regards,
Laktronics
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
04 Feb 2008 13:00 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| laktronics wrote: |
Hi,
A small correction regarding Watchdog Timer. It is a timer which has to be constantly triggered by the microcontroller at regular intervals to prevent it from producing an output pulse. If the controller fails to do it due its program losing control for some reason, the pulse output from the watchdog is used to reset the micro, thus ensuring that the micro recovers from its hanging state. It is a circuit that works like a watchdog on the proper working of the micro. You may or not, use it in your application.
Regards,
Laktronics |
hi laktronics,
thanks for clearing it bit deeply
can i use it in my application..??
if yes then please give me some detailed description...
Thank you.
noboady is ready to help..???
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
06 Feb 2008 8:03 RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
i am using RTC DS1307 and EEPROM AT24C02 - both are sharing same I2C lines.
so how can i differentiate them in codeing and data transferring.??
|
|
| Back to top |
|
 |
laktronics
Joined: 06 Jan 2007 Posts: 793 Helped: 134
|
06 Feb 2008 10:42 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Hi,
Ok, you can add a watchdog to your design. This can be done using a retriggerable monoshot which will be triggered using a port pin of S52. In your software, you have to ensure that you do this triggering regularly within a fixed interval say 10 millisec. In that case you design a monoshot with a pulse width >10msec, say 15 msec. Whenever the mono output goes to zero due to failure of CPU to trigger it, generate a reset pulse for your CPU.
You can also implement a watchdog with a counter counting a clock input. In this case, use the CPU port pin to reset the counter at regular intervals and should the counter count and overflow at any time, use the overflow output to reset the CPU.
And to H_D_R, use an external address other than '000', reserved for RTC for addressing 24C02.
Regards,
Laktronics
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
06 Feb 2008 11:57 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| laktronics wrote: |
Hi,
Ok, you can add a watchdog to your design. This can be done using a retriggerable monoshot which will be triggered using a port pin of S52. In your software, you have to ensure that you do this triggering regularly within a fixed interval say 10 millisec. In that case you design a monoshot with a pulse width >10msec, say 15 msec. Whenever the mono output goes to zero due to failure of CPU to trigger it, generate a reset pulse for your CPU.
You can also implement a watchdog with a counter counting a clock input. In this case, use the CPU port pin to reset the counter at regular intervals and should the counter count and overflow at any time, use the overflow output to reset the CPU.
And to H_D_R, use an external address other than '000', reserved for RTC for addressing 24C02.
Regards,
Laktronics |
thanks.
but it sounds quite complicated for me.
i think i have to read much more and more about watchdog.
if you dont mind please tell me something regarding my project now bcoz then and only then i can use it.
Thanks a gain for replying.
|
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
06 Feb 2008 13:34 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Hi H_D_R
I don't think you need a watchdog to get the DS1307 working.
Check fig 4 & fig 5 on the bottom of page 12 of the DS1307 datasheet.
The first byte is the address of the DS1307 on the I²C bus.
When you want to read/write from/to the DS1307 you always need to send that byte first.
On the AT24C02 you have three pins A0 - A2 to setup a certain address. Connect these pins to Vcc/Gnd so that you have a different address than that from the DS1307.
Since the 4 higest bits are different in DS & AT, you can connect all three pins to GND.
That way you get:
address 1010 000x for the AT24C02
address 1101 000x for the DS1307
Clear? No ... ask
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
07 Feb 2008 13:27 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
hello,
Can any one please help me to understand this Paragraph. it is from RTC DS1307 Page no.8
| Quote: |
"When reading or writing the time and date registers, secondary (user) buffers are used to prevent errors when the internal registers update. When reading the time and date registers, the user buffers are synchronized to the internal registers on any I2C START. The time information is read from these
secondary registers while the clock continues to run. This eliminates the need to re-read the registers in case the internal registers update during a read. The divider chain is reset whenever the seconds register is written. Write transfers occur on the I2C acknowledge from the DS1307. Once the divider chain is reset,
to avoid rollover issues, the remaining time and date registers must be written within one second." |
please tell me what is the meaning of this bold words used here.
i am little bit confused about it.
Thanks
|
|
| Back to top |
|
 |
laktronics
Joined: 06 Jan 2007 Posts: 793 Helped: 134
|
07 Feb 2008 19:29 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Hi,
This only means that the time that you read from the RTC is the time at the start condition of I2C. This is ensured in the chip by having a set of user registers which will be updated from the actual time counting registers at the start condition.
Reading a register like the time counting register which changes asynchronously with read signal is otherwise always a probblem. See for example the case of the time register containing a vlue of 12:59:59. and you imagine soon after reading minutes and seconds, a seconds pulse has occurred at the input and the timer register changed to 1:00:00 value. Now if you read the hour register, you will get the total reading as 1:59:59 which is wrong. To avoid this condition,the chip ensures that you read only from the user buffer which will not be updated in the middle of a reading.
Similarly while setting the time, you start setting from seconds onwards, the clock divider chain ahead of 1 second pulse output gets reset so that you get one full second duration to load other time digits before the next update occurs. Here you are actually loading the running registers and not a buffer register.
Regards,
Laktronics
|
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
07 Feb 2008 19:30 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Looking at figure 1 the block diagram on page 4 you can see three blocks on the right side
upper block: 56 bytes of internal RAM address 08h to 3Fh
middle block: 8 control registers used by the DS address 00h to 07h
lower block: 7 so called "user buffer"
When you read from the DS, the data from the 8 control registers is copied into the user buffer and you read from that buffer. Copy starts with the START command on the I²C bus.
When you write to the DS, your data goes first to the user buffer, when all data is received it is copied into the 8 control registers.
Bottom line: don't worry about it, it's all internal stuff handled by the DS.
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
09 Feb 2008 8:44 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
hello,
can any one please help me to clear this doubt.
Datahseet Ds1307 Page no:11
| Quote: |
| Data transfer from a slave transmitter to a master receiver. The first byte (the slave address) is transmitted by the master. The slave then returns an acknowledge bit. This is followed by the slave transmitting a number of data bytes. The master returns an acknowledge bit after all received bytes other than the last byte. At the end of the last received byte, a “not acknowledge” is returned. |
here how the master will recoginze the last bit.please read the Bold line
sorry to divert from my main thread of project line
and asking question but this is also necessary to understand and easy implementation.
Thank you to all...!!
PS:: i have understood the reason for the bold line. please help me for next step.
thanks
Added after 38 minutes:
thanks mcs51mc,
i have got the idea of I2C in RTC more clearly but still some doubts.
by the way, i have got solution of my last question in this thread also.
but now, i have to implement.
so can anyone tell me from where i have to start.
i have made interfacing of 4 serial keys and LCD with my 89S52 successfully.
i have tested code on circuit also and working properly.
i have taken 4 switches for following purpose:
1- Up,
2- Down,
3- Set-time,
4-Set-Alarm.
now the only thing is left RTC DS1307.
is there anybody who can help..??
Thanking you all for reply and suggestions.
Last edited by H_D_R on 11 Feb 2008 8:45; edited 1 time in total |
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
09 Feb 2008 20:27 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Check this one: http://www.sixca.com/micro/mcs51/rtc_51/
Hope it helped
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
11 Feb 2008 10:21 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| mcs51mc wrote: |
Check this one: http://www.sixca.com/micro/mcs51/rtc_51/
Hope it helped  |
Thanks for this link.
but i have visited already and it has code in C language programming.
and i am using ASM language...
any way, Thanks
|
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
11 Feb 2008 18:48 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
I know it's C but with the free Keil C compiler you can compile it and get the ASM code from it  
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
12 Feb 2008 4:47 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| mcs51mc wrote: |
I know it's C but with the free Keil C compiler you can compile it and get the ASM code from it    |
ya i can do in that way, but it will be quite difficult as i dont have command on C.
and Keil too..
can any body help..??!!!
thanks for trying your best to help me..
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
13 Feb 2008 12:51 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
hello all,
can any one please tell me how can i store the time values in RTC...???
i have read I2C and datasheet of RTC also.
but still little bit confused..??
can any one please help...???
|
|
| Back to top |
|
 |
laktronics
Joined: 06 Jan 2007 Posts: 793 Helped: 134
|
13 Feb 2008 15:30 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Hi,
I am sorry, I should have advised you this earlier, you should get everything about 8052 at www.8052.com. You should visit their code section, and I am sure your clock should me ticking over there, may be you have to join the forum to go to code section.
Regards,
Laktronics
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
14 Feb 2008 5:40 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| laktronics wrote: |
Hi,
I am sorry, I should have advised you this earlier, you should get everything about 8052 at www.8052.com. You should visit their code section, and I am sure your clock should me ticking over there, may be you have to join the forum to go to code section.
Regards,
Laktronics |
so, this is the reason for lots of threads of RTC left incompleted by users...??
|
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
14 Feb 2008 8:46 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
I never used the DS1307 RTC so I'ts just a guess after reading pages 11 to 13 of datasheet.
As I understood the text you need to send this data to write to the RTC:
1) generate a start condition
2) send the address of the DS1307 and the R/W bit : 11010000
3) generate an extra SCL pulse and check for ACK bit from RTC
4) ACK ok then send an address byte (see table 2 for addresses) 01h for minutes
5) generate an extra SCL pulse and check for ACK bit from RTC
6) ACK ok then send the minutes data (0101 1001 for 59 minutes)
7) generate an extra SCL pulse and check for ACK bit from RTC
generate a stop condition
To read something from the RTC follow the same steps
1) generate a start condition
2) send the address of the DS1307 and the R/W bit : 11010001
3) generate an extra SCL pulse and check for ACK bit from RTC
4)ACK ok then read the minutes data
5) generate an extra SCL pulse and check for ACK bit from RTC
6) generate a stop condition
Why do you read the minutes in the above sequence?
Because your last write was to that register.
If you want to read another register you need to build up a sequence according to figure 6.
First a write to set a register in the RTC then a read to read the data from that register. Of course wit all start/stop/ACK stuf in between.
I agree that figures 4 to 6 are a littke confusing because of the Data(n), Data(n+1) stuff but according to the text you can send/receive only one byte at the time.
I think the RTC laks an auto incrementing pointer so that you could read/write consecutive addresses without setting the address first.
If it doesn't work, don't shoot me, re-read the first sentence of this post
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
14 Feb 2008 9:41 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Thank you mcs51mc,
  hello, i am not going to shoot anyone...
i am requesting for help not ordering...
i understand these all thing and i am on the way of implementing the clock already.
hope so i'll be able to complete atleast read/write operation till tonight..!!
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
18 Feb 2008 5:05 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
hello every one..
one good news is there..
i have got success in making clock.
but still i have to add alarm and not a single but four alarm...??
so ithere anybody who can help me ittle bit..
i am facing problem to store alarm..
thanks to you all for helping me....
|
|
| Back to top |
|
 |
vietdung79
Joined: 01 Aug 2007 Posts: 31 Helped: 5 Location: Hanoi City, Vietnam
|
18 Feb 2008 5:33 RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| Try some Voice Recorder ICs such as ISD2560.
|
|
| Back to top |
|
 |
vietdung79
Joined: 01 Aug 2007 Posts: 31 Helped: 5 Location: Hanoi City, Vietnam
|
18 Feb 2008 5:33 RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| Try some Voice Recorder ICs such as ISD2560.
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
18 Feb 2008 8:00 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
| vietdung79 wrote: |
| Try some Voice Recorder ICs such as ISD2560. |
THANKS FOR THE INFORMATION..
BUT FOR YOUR KIND INFO. I WANT TO DISPLAY UPDATES ON LCD AND LED.
I JUST WANT TO GLOW LED.
SO NO NEED TO USE THIS IC.
BY THE WAY I AM HAVING PROBLEM ONLY TO STORE THE ALARM TIME IN RTC.
CAN ANYBODY HELP ME...???
Last edited by H_D_R on 18 Feb 2008 10:19; edited 1 time in total |
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
18 Feb 2008 8:50 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
One problem down... ... n to go 
Correct me if I'm wrong but the DS doesn't have any alarm time registers so where do you think to store the alarm time?
What was your idea about storing time and compare actual time & alarm time?
My basic idea is:
1) EEPROM to store all alarm times (day of week, hour, minute (, second)).
2) On second or minute basis compare actual time and alarm times.
3) Use PC to download alarmtimes into clock.
|
|
| Back to top |
|
 |
H_D_R
Joined: 31 Jan 2008 Posts: 361 Helped: 17 Location: India
|
18 Feb 2008 10:13 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
thanks for reply mcs51mc
| Quote: |
| Correct me if I'm wrong but the DS doesn't have any alarm time registers so where do you think to store the alarm time? |
sir, i know there is no register to store the alarm time but it has 56bytes user space, where we can store the time.
and i am also using that only.
| Quote: |
What was your idea about storing time and compare actual time & alarm time?
My basic idea is:
1) EEPROM to store all alarm times (day of week, hour, minute (, second)).
2) On second or minute basis compare actual time and alarm times.
3) Use PC to download alarmtimes into clock. |
i am not using PC to store the real time.
i am setting real time mannually through key pad.
can you help me....????
|
|
| Back to top |
|
 |
mcs51mc
Joined: 19 Jul 2007 Posts: 73 Helped: 16 Location: Belgium
|
18 Feb 2008 13:29 Re: RTC DS1307 Interfacing with MCU 89S52 |
|
|
|
Since you enter real time through keypad, you can also enter alarm times through keypad
Do you want accuracy of alarmtime on second or minute level?
I mean is alarmtime 07:25 ok or do you need 07:25:35?
Do you need alarmtime based on day of week or not?
Same time for all days of week or not?
The answers to the above questions will determine which data needs to be stored in the 56 bytes of RAM.
Please keep in mind that you will need a battery backup or all you alarms will be gone at the first power down
One alarmtime can looks like:
Byte 0: 3 bits = day of week -- 5 bit = alarm hour in 24 hour system
OR
Byte 0: 3 bits = day of week -- 1 bit = AM/PM -- 4 bit = alarm hour in 12 hour system
Byte 1: alarm minute
Byte 2: alarm second if needed
You need 4 alarms? That's 8 or 12 bytes in RAM.
Endless loop in your µC:
Read actual time
Read alarm time 1 : compare with actual time : if needed set alarm bit
Read alarm time 2 : compare with actual time : if needed set alarm bit
Read alarm time 3 : compare with actual time : if needed set alarm bit
Read alarm time 4 : compare with actual time : if needed set alarm bit
|
|
| Back to top |
|
 |