Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem in interfacing msm6242b with at89c52

Status
Not open for further replies.

esconele

New Member
hello everybody,
i'm interfacing MSM6242B ITS A RTC WITH at89c52 FOR DISPLAYING TIME AND DATE ON LCD IN 00:00:00 DD:MM:YY FORMAT HERE I'VE CONNECTION LIKE THIS
FOR MSM6242B
STD.P IS OPEN
ALE =VDD
A0-A3 ARE CONNECTED TO PORT2 P2.4_P2.7
D0-D3 ARE CONNECTED TO PORT2 P2.0-P2.3
TRD-P0.7
TWR-P0.6
CS0-P0.5
CS1-P0.4
CODE:
MOV A,#0FH
MOV P2,A ;MAKING PORT2 P2.0-P2.3 INPUT PINS
MOV A, #00H
MOV P2,A
RCALL READRTC
;OTHER REGISTERS LIKE MINUTES,HRS.... ARE READ AS SAME
READRTC:
SETB CS1
CLR CS0
CLR TRD
MOV VALUE,P2
SETB TRD
SETB CS0
CLR CS1
RET

BUT ITS NOT GIVING THE RESULTS ALSO I TRIED TO WRITE TO RTC BUT ITS NOT WORKING .AND IS IT NECESSORY TO WRITE TO D,E AND F REGISTERS PLS HELP ME IF ANY ONE HAVE ANY IDEA ABOUT THIS PLS REPLY
THANK YOU.
 
Do you need pullup resistors on the PORT 0 pins? They probably are open drain outputs, but you knew that, right?

Writinga 0x0F to Port 2 followed by writng a 0 to port 2 looks a bit suspicious. Are you sure that is waht you wanted to do?
 
interfacing msm6242b with at89c52

sir,
actually first i wanted to make port2 lower bit as input port and then after i want to load seconds register address which is 00 for first and then i'm taking input from lower bit of port2 even if i do like this
mov a,#0fh
mov p2,a ;;; making port2 lower byte as input
mov address,#00h
call readrtc
;;
readrtc:
mov p2,address
clr trd
mov value,p2
setb trd
ret

then also its not giving the results i've given pull up to port0 what about cs0 and cs1 pins these pins are setted to high only and ALE of RTC is connected to VDD and is it necessory to write to D,E,F registers of RTC MSM6242 pls help me
 
I'm having a hard time understanding what you are doing. This is not uncommon when there is no schematic diagram. Natural languages are very poor methods for describing circuits.

About one thing I am quite certain though, connecting ALE to Vdd sounds like a really bad thing to do.

A peripheral device with a multiplexed bus needs the falling edge of ALE to define a valid register address. ALE won't go low in your circuit.
 
interfacing msm6242 with at89c52

sir,
actually in datasheet of msm6242b it is given that we can connect ALE to VDD thats why i've made connections like this i've check the datapins for both at89c52 and msm6242b and data is there on data pins but when i read the data for respective registers it gives only that number which i've written last to rtc like if i've written
mov addr,#00h ; addres of second1 register
mov data,#03h
setb cs1
clr cs0
mov p2,addr
clr twr
mov p2,data
setb twr
setb cs0
clr cs1
and now if i read data from rtc like
mov addr,#01h ;address of second2 register
setb cs1
clr cs0
mov p2,addr
clr trd
mov data,p2
setb trd
setb cs0
clr cs0
then it gives number 3 for every other registers
what connection should be make to ALE pin of rtc kindly give me any sample code for this when writing or reading rtc what status should be there on cs1 and cs0 pins what i'm doing is correct or wrong pls suggest me the solution
thank you
 
It sounds like the RTC can be interfaced to different types of processors. Some of the processors have a multiplexed address/data bus and some processors have separate address/data busses. If the address and data busses are separate then tying ALE to Vdd may be appropriate. You are not using the actual address/data bus of the AT89C52, but are using a port to synthesize a bus transaction. You need to do two things:

1. Understand how the AT89C52 creates a bus transaction for reading and writing external memory. You want to mimic theses signals with port pins, but at a much slower rate.

2. Understand how to configure the RTC as if you were using the actual AT89C52 bus transactions. Then using the port pins should look exactly the same, except slower.

The problem that you describe sounds like not being able to get a register address into the chip, so you always read back the content of the default address which is the same as the last thing you wrote.
 
interfacing msm 6242b problem

sir,
herewith i've attached ckt diagram for msm6242 and 89c52 with the same ckt one of my frend wrote a program and getting time and date but i'm not getting where i'm wrong i'm going in the same way as frend only the differenc in ckt is i'm using 32.78khz crystal for rtc and 12Mhz for 89c52 whereas frend used 4Mhz for rtc and 12 Mhz for 89c52 should i increase the crystal value but recomended value is 32.78khz and is it necessory to give high to low pulse on cs0 and cs1 pins for reading and writing pls suggest me the solution
thank you.
 

Attachments

  • MSM.JPG
    MSM.JPG
    23.5 KB · Views: 352
Do you know how to read the timing diagram in Figure 4 of the MSM6242B datasheet? Have you complied with the setup and hold times required of CS1 and CS0, and can you confirm this with an oscilliscope?

To make a valid transaction you need to study the timing diagrams in the datasheet. As I see it you need to take CS1 high for the whole transaction. You need 1 usec = 1000 nsec before the address bits and CS0 change. How do you ensure that? After the transaction is complete there is a address hold time before CS1 goes low. How do you ensure that?

I seriously doubt that your friend used 4 MHz as the crystal for the RTC.

You realize that this part is obsolete and not recommended for new designs, right?
 
Last edited:
msm6242b interfacing problem

sir,
now i connected ALE PIN OF RTC TO P0.4 AND IN CODE WHEN WRITING ADDRSS I'VE GIVEN HIGH TO LOW TRANSACTION TO THIS PIN BUT STILL ITS NOT GIVING THE RESULTS PLS TELL ME WHERE I'M WRONG
WHAT I'M DOING IS LIKE THIS

INITRTC:
MOV A,#0F5H ;HOLD=1;24/12=1
CALL TWRITE
MOV A,#0F4H ;HOLD=0;24/12=1
CALL TWRITE
MOV A,#0E0H
CALL TWRITE
MOV A,#D4H ;IRQ=1
CALL TWRITE
RET
READALL:
MOV A,#00H ;SECOND1 REG ADDRESS
CALL READRTC
ANL A,#0FH
MOV 3FH,A
MOV A,#10H ;SECOND10 REG ADDRESS
CALL READRTC
ANL A,#07H
MOV 3EH,A
RET
TWRITE:
SETB CS1
CLR CS0
SETB TALE ;TALE IS DEFINED AS FOR P0.4
MOV P2,A
CLR TALE
CLR TWR
MOV P2,A
NOP
NOP
SETB TWR
SETB CS0
CLR CS1
RET
READRTC:
SETB CS1
CLR CS0
SETB TALE
MOV P2,A
CLR TALE
CLR TRD
NOP
NOP
MOV A,P2
SETB TRD
SETB CS0
CLR CS1
RET
 
Starting with the TWRITE routine. How do you guarantee that 1 microsecond elapses between the rising edge of CS1 and the falling edge of CS0 as required by the RTC and mentioned in it's data sheet. If I knew or could remember what your clock frequency was it would help. Now that you have gone and connected ALE I'll have to look at the next picture in the datasheet.

You need to review the timing diagram for the RTC and match that to the instruction execution time in the processor. If you coud see the results on an oscilliscope it would help you a great deal.
 
msm6242 problem

sir,
somewhere i saw a program for interfacing msm6242b with pic16f84 in that they didn't used cs0,cs1 these pins were kept always high i tried it in my program but didn't get results sould i connect ALE OF MSM TO ALE OF MICROCONTROLLER THEN HOW I CAN GIVE HIGH TO LOW TRANSITION
IF U HAVE ANY SAMPLE CODE THEN PLS GIVE ME IDEA
THANK YOU.
 
As I said before I have no sample code for this device. I have worked with other similar devices and the key to making them work is to duplicate the timing diagrams in the datasheet in excruciating detail. Making the time between events on a timing diagram longer is generally not a problem. Making them shorter is fatal. If you do not have a scope to help you see what is going on then you must analyze your program's timing on an instruction cycle basis.

For Example:

SETB is a 2 Byte 1 cycle Instruction. If you know the oscillator frequency and the number of oscillator cycles per instruction then you can compute how long it takes for the bit to be set.
CLR is also a 2 byte 1 cycle instruction so you can see there is one instruction cycle between the SETB CS1 and the CLR CS0. Question, is this time more or less than 1 microsecond. If the answer is no, then write
Code:
  SETB  CS1
  NOP
  CLR   CS0
  NOP
This makes the time from the rising edge of CS1 to the falling edge of CS0 equal to two instruction cycles. Question, is this time more or less than 1 microsecond.

I would recommend that you go back to tying ALE on the RTC high, especially since you don't seem to have a scope and don't seem to be familiar with timing diagrams and timing requirements.
 
Last edited:
msm6242b interfacing problem

sir,
in the following code its giving the data which i've writen in the respective
registers but there is no increment in the values its always showing the same data what are the steps to read rtc pls suggest me.THE OUTPUT IS LIKE TIME: 12:51 , DATE:12:05:06
thank you
org 0000h
main:
CALL INIT_RTC
CALL RTC_WRITE
HERE:
CALL READ_RTC
SJMP HERE



INIT_RTC:
MOV A,#0F5H
CALL TWRITE
MOV A,#0F4H
CALL TWRITE
MOV A,#0E0H
CALL TWRITE
MOV A,#0D4H
CALL TWRITE
RET

RTC_WRITE:
MOV A,#21H
CALL TWRITE
MOV A,#35H
CALL TWRITE
MOV A,#42H
CALL TWRITE
MOV A,#51H
CALL TWRITE
MOV A,#62H
CALL TWRITE
MOV A,#71H
CALL TWRITE
MOV A,#85H
CALL TWRITE
MOV A,#90H
CALL TWRITE
MOV A,#0A6H
CALL TWRITE
MOV A,#0B0H
CALL TWRITE
RET
READ_RTC:
MOV A,#20H
CALL READ
ANL A,#0FH
MOV 3AH,A
MOV A,#30H
CALL READ
ANL A,#07H
MOV 3BH,A
MOV A,#40H
CALL READ
ANL A,#0FH
MOV 3CH,A
MOV A,#50H
CALL READ
ANL A,#03H
MOV 3DH,A
MOV A,#0D0H
CALL TWRITE

RET
TWRITE:
CLR CS1
CLR CS0
NOP
SETB CS1
NOP
SETB CS0
MOV P2,A
NOP
CLR CS0
CLR TWR
MOV P2,A
NOP
NOP
SETB TWR
NOP
CLR CS1
RET
READ:
CLR CS1
CLR CS0
NOP
SETB CS1
NOP
SETB CS0
MOV P2,A
NOP
CLR CS0
CLR TRD
MOV A,P2
NOP
NOP
SETB TRD
NOP
CLR CS1
RET
 

Attachments

  • MSM.JPG
    MSM.JPG
    23.6 KB · Views: 268
Last edited:
If you had an oscilliscope you could see if the oscillator was running.

I see that you are writing a 5 then a 4 to register F which should reset the fractional seconds counter.
I see that you have written a 0 to register E. Is there any kind of waveform at the STD.P pin, pin 1?
I see that you are writing a 4 to register D which should clear the hold bit.
I can't see anything that would prevent the clock from running.
Sorry.

Edit: Why do you think this poor CMOS part will work at 4MHz. Where did this quaint notion come from?
 
Why do you need a RTC just to display date and time?

Your 8051 based IC has internal timer functions. If you can determine how to use them and embed them in your code, then you will only need all of port 1 for the 8-bit data output, and Port P3.7 and Port P3.6. One for enable pin and one for the data/command pin. I assume here your LCD is HD47780 compatible (standard character LCD).

I think your AT89C52 has internal program ROM. If not, you can connect external ROM to it and use that, provided the chip supports it. If it has internal rom, then the only other external components you need are the oscillator circuitry (at minimum, 2 capacitors, and a crystal), the LCD, a decent, and regulated 5V power source, and a pull-down resistor for the LCD enable line.
 
Hi esconele,

Papabravo said:
I have worked with other similar devices and the key to making them work is to duplicate the timing diagrams in the datasheet in excruciating detail.

What is said by Papabravo is the one and only piece of important advice that you have to follow exactly to the letter.

I looked back at the coding I made for M6242B and found that several things that you have not done, yet. I marked them with "<<<<<<" in the code I posted.

1. hold/stop the RTC before changing its registers or operating mode
2. wait the required time(I mostly waited longer) that specified in the datasheet
3. only issue commands to the RTC when it can accepts it(not busy)

And finally, do yourself a favour. Write your code properly with lots of comments so even after many years, the codes still means something when you read it again.

Here is part of my code that I have used. 11.0592MHz for MCU and 32.768KHz for RTC. The codes is different to what you'll need as I also have external EPROM,SRAM & LCD connected to the databus too, so the RTC registers are memory mapped to appear as memory locations.

Code:
;#################################################################
;
;SUBROUTINES - rtc_init				       
;
;FUNCTION: Read	data from 8052 time/date buffer	and put
;          into RTC registers
;
;   ENTRY: new RTC timing data ready in 80C32 RAM
;    EXIT: nil
;   USING: a,r0,r1
;PRESERVE: a,r0,r1
; DESTROY: 
;  AFFECT: flags
;
; CALLING: wait_250us 
;	   
;#################################################################
;
rtc_init:
	push a
	push 00h
	push 01h
	;
	clr p2.7
	mov r0,#rtc_d		;select	rtc reg	D
        mov a,#00000001b        ;data to hold RTC count <<<<<<<<<<
	movx @r0,a		;send to RTC
	;
	call wait_250us		;wait  <<<<<<<<<<
$rtc1:  movx a,@r0              ;read back status
	jb acc.1,$rtc1		;is RTC	busy <<<<<<<<<<
	jb acc.1,$rtc1
	;
	mov r0,#rtc_f		;set address of	RTC F register
        mov a,#00000101b        ;select 24 Hour mode
	movx @r0,a		;send to RTC with Reset	Bit set
	call wait_250us
        mov a,#00000100b
	movx @r0,a		;lower Reset bit
	;
	;now check whether we can put data into	RTC timer registers
	;
	mov r0,#rtc_d		;status	register
$rtc2:	call wait_250us
	movx a,@r0		;read from RTC status register
	jb acc.1,$rtc2		;loop until RTC	not busy
	jb acc.1,$rtc2
	;
	;Now RTC not busy
	;
        mov r1,#rtc_sec         ;start of time data register
	;
        mov a,cur_sec           ;get curent seconf value
;
;
;
 
msm6242b problem

sir,
i cheked the oscillator its working and the std.p pin is low all times data is also there on data pins but counter doesnts give the incremented time why
pls help me
thank ypu
 
msm6242 problem

sir,
i've worked a lot on this but still i'm not getting the results where i'm wrong ?
data is there on chip data pins i checked with oscilloscope but when i read it its not giving why pls help me here is the code pls suggest me the solution

org 0000h
main:
call INIT_MT
LOOP:
CALL FINE1
CALL DISPLAY_TIME
SJMP LOOP



INIT_MT:
PUSH ACC
PUSH 00H
PUSH 01H
MOV R0,#0D0H
MOV A,#00000001B ;; HOLD=1
CALL TWRITE

CALL WAIT250US
$RTC1:MOVX A,@R0
JB ACC.1,$RTC1 ;CHECK FOR BUSY BIT
JB ACC.1,$RTC1
MOV R0,#0F0H
MOV A,#00000101B ;24 HR MODE,RESET=1
CALL TWRITE
CALL WAIT250US
MOV A,#00000100B ;24 HR MODE RESET=0
CALL TWRITE
;CALL WAIT250US
MOV R0,#0D0H
$RTC2:CALL WAIT250US
CALL TWRITE
JB ACC.1,$RTC2 ;CHECK FOR BUSY
JB ACC.1,$RTC2
MOV R1,#50H ;HR10 REG ADDRESS
MOV A, #00000001B ; SET HR10 = 1
CALL TWRITE
CALL WAIT250US
MOV R1,#40H ;HR1 REG ADDRESS
MOV A,#00000010B ;SET HR1 = 2
CALL TWRITE
CALL WAIT250US
MOV R1,#40H ;MIN10 ADDRESS
MOV A, #00000100B ;SET MIN10 = 4
CALL TWRITE
CALL WAIT250US
MOV R1,#30H ;MIN1 ADDRESS
MOV A,#00000101B ;SET MIN1 =5
CALL TWRITE

RET

FINE1:
MOV R1,#060H ;READ DAY1 REG

LCALL READRTC
ANL A,#0FH ;ONLY LOWER BYTE
MOV 3FH,A


MOV R1,#070H ;READ DAY10 REG

LCALL READRTC
ANL A,#03H ;ONLY LOWER 2 BITS
MOV 3EH,A

MOV R1,#020H ;READ MIN1 REG

LCALL READRTC
ANL A,#0FH ;LOWER BYTE ONLY
MOV 3DH,A

MOV R1,#030H ;READ MIN10 REG
LCALL READRTC
ANL A,#07H ;LOWER 3 BITS
MOV 3CH,A

MOV R1,#040H ;;HOUR1 REG

LCALL READRTC
ANL A,#0FH
MOV 3BH,A

MOV R1,#050H ;HOUR10 REG READ

LCALL READRTC
ANL A,#03H
MOV 3AH,A
MOV R1,#080H ;MONTH1 REG READ

LCALL READRTC
ANL A,#0FH
MOV 39H,A

MOV R1,#090H MONTH10 REG READ

LCALL READRTC
ANL A,#01H
MOV 38H,A

MOV R1,#0A0H ;READ YEAR1 READ

LCALL READRTC
ANL A,#0FH
MOV 37H,A

MOV R1,#0B0H ;READ YEAR1 REG

LCALL READRTC
ANL A,#0FH
MOV 36H,A

RET
;AS PER TIMING DIAGRAM TWRITE AND READRTC FUNCTIONS ARE WRITTEN
TWRITE:
clr CS0
clr CS1
nop
nop
nop
nop
SETB CS1
nop
setb CS0

nop
clr CS0
nop
CLR TWR
MOVX @R1,A
CALL WAIT250US
NOP
SETB TWR

nop
nop
CLR CS1
RET


READRTC:

clr CS1
clr CS0
nop
nop
nop
nop
SETB CS1
nop
setb CS0
nop
nop
nop
CLR CS0
nop
CLR TRD
NOP
MOV A,@R1
nop
CALL WAIT250US
SETB TRD
nop
nop
CLR CS1


RET
WAIT250US:MOV 34H,#07DH
DF1: DJNZ 34H,DF1

RET
 
esconele said:
sir,
i've worked a lot on this but still i'm not getting the results where i'm wrong ?
data is there on chip data pins i checked with oscilloscope but when i read it its not giving why pls help me here is the code pls suggest me the solution

Of course your code would not work. The MOVX command requires ALE, WR and RD signals for it to work. In order to use the MOVX command, you have to connect your RTC as shown.

The ALE, WR and RD signals already existed as standard signals in the 89C52, so why would you want to generate it yourself. You just made your life so much difficult.

With the connections shown, you can use the same method in my code to access the registers on the RTC. Good luck to you.
 

Attachments

  • RTC.gif
    RTC.gif
    7.8 KB · Views: 305
Last edited:
msm probnlem

sir,
thank you for helping me.
but in your code you are not doing anything with RD WR AND ALE pins but in datasheet it is ghiven that there should be high to low high transaction on WR AND RD pins while writing and reading and CS0 should be low can i use the ffunctions i've written for reading and writing purpose or your code will give the results.thanks a lot sir
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top