Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

eeprom bits are missing out

Status
Not open for further replies.

lats

Full Member level 4
Joined
Oct 27, 2005
Messages
217
Helped
13
Reputation
26
Reaction score
6
Trophy points
1,298
Activity points
2,958
Hello everybody,
i'm writing some values from 89c51 to eeprom 24c02 but the bits are missing out. I've checked the eeprom routines , i even tried out increasing the delays. I've connected SCL & SDA pins of EEPROM on port P1, Tried connecting different pull-up resistors also (10k, 4.7k, 2.2k and even Zero resistor) but coundln't get the result what can be the problem please help me out. thnx
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
I would suggest two things:
- If you have a chance get a dual-channel ocilloscope and try to "watch" what is actually happening on SCK and SDA lines; can you really observe "missing bits"? ..
- post you code; I am pretty sure someone will be as keen as mustard to verify it ..

Regards,
IanP
 

lats

Full Member level 4
Joined
Oct 27, 2005
Messages
217
Helped
13
Reputation
26
Reaction score
6
Trophy points
1,298
Activity points
2,958
thnx Ianp for replying. below is the code. i took much part of it from a application file from www.maxim-ic.com
Code:
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

DELAYNS:                        
;                               
   	MOV  DR7,#00H                
LOOPD:                          
   	INC  DR7                     
   	MOV  A,DR7                   
   	CJNE A,#0FFH,LOOPD
	RET
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DELAYRS:                        
   	MOV   DR6,#046H          
   	MOV   DR5,#001H               
LOOPC:
	JB START_STOP_INT, RET_DELAY
   	JB MENU_INT, RET_DELAY
   	INC   DR6                     
   	ACALL   DELAYNS              
   	MOV   A,DR6                   
   	JNZ   LOOPC                  
   	DEC   DR5                    
   	MOV   A,DR5                  
   	JNZ   LOOPC                  
RET_DELAY:
   	RET
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx





;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
READ_EEPROM:
	
	ACALL DELAYRS
	
	MOV R0, #42H		;start writing from 42h location of 89c51 RAM
	MOV EE_ADDR, #00H	;start writing to 00h location of EEPROM
	MOV R3, #02H		;to read 2-bytes, i.e from 42h to 43h,
				

BACK_READ:
	ACALL EE_READ
 	MOV @R0, EE_DATA

	INC R0
	INC EE_ADDR
	
	DJNZ R3, BACK_READ

	MOV R0, #42H
	MOV EE_ADDR, #00H
	MOV R3, #02H
	RET
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
WRITE_EEPROM:
	MOV R0, #42H
	MOV EE_ADDR, #00H
	MOV R3, #02H
	

	
BACK_WRITE:
	MOV EE_DATA, @R0
	ACALL EE_WRITE

	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS
	ACALL DELAYNS

	
	INC R0
	INC EE_ADDR
	
	DJNZ R3, BACK_WRITE
	
	MOV R0, #42H
	MOV EE_ADDR, #00H
	MOV R3, #02H
	RET
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

EE_WRITE: 	ACALL	EE_START 	; SEND A START FLAG TO THE EEPROM
	MOV	A,#0A0H			; SPECIFY A WRITE EEPROM @ ADDRESS 0H
	ACALL	SHOUT 			; SHIFT OUT THE DEVICE ADDRESS
	JC	WR_ABORT		; ABORT IF NO ACK FROM EEPROM
	MOV	A,EE_ADDR		; GET EEPROM MEMORY ADDRESS
	ACALL	SHOUT			; SHIFT OUT THE MEMORY ADDRESS
	JC	WR_ABORT		; ABORT IF NO ACK FROM EEPROM
	MOV	A, EE_DATA		; GET THE DATA TO BE WRITTEN
	ACALL	SHOUT 			; SHIFT OUT THE DATA
	JC	WR_ABORT		;
	CLR	C			;
WR_ABORT: 	
	ACALL	EE_STOP			; SEND STOP CONDITION TO EEPROM
					; WAIT FOR WRITE TIME OF THE 24C02 {10ms}
					; THE EEPROM TAKES 10ms TO INTERNALLY STORE THE DATA. YOU CAN EITHER
					; PUT THE MICROCONTROLLER IN A WAIT STATE, OR CONTINUE WITH EXECUTION,
					; KEEPING IN MIND THAT THE EEPROM DATA IS NOT STORED FOR 10ms! 

	RET				; GO BACK TO MAIN PROGRAM
					; READ THE EEPROM DATA - FIRST PERFORM 'DUMMY WRITE'
EE_READ:	
	MOV	EE_DATA,#00H		; CLEAR OLD DATA
	ACALL	EE_START		; SEND A START FLAG TO EEPROM
	MOV	A,#0A0H			; SPECIFY A WRITE TO EEPROM @ ADDRESS 0H
	ACALL	SHOUT			; PERFORM 'DUMMY WRITE'
	JC	RD_ABORT		; ABORT IF NO ACK
	MOV	A,EE_ADDR		; LOAD EEPROM MEMORY LOCATION
	 				; FROM WHICH TO READ
	ACALL	SHOUT			; WRITE EEPROM MEMORY LOCATION
	JC	RD_ABORT		; ABORT IF NO ACK
					; NOW READ THE DATA!
	ACALL	EE_START		; SEND A START FLAG
	MOV	A,#0A1H			; SPECIFY A READ FROM EEPROM
	ACALL	SHOUT 			; SHIFT OUT EEPROM ADDRESS
	JC	RD_ABORT		; ABORT IF NO ACK
	ACALL	SHIN			; SHIFT IN THE DATA FROM EEPROM
	MOV 	EE_DATA,A		; STORE THE DATA
	ACALL	NAK			; SEND A NAK (NO ACKNOWLEDGE) TO THE
					; EEPROM
	CLR	C			; CLEAR ERROR FLAG

RD_ABORT:	
	ACALL	EE_STOP			; ALL DONE
	RET				;
					; EE_START BIT-BANGS A START SEQUENCE TO EEPROM (HI-TO-LOW SDA TRANSITION 
					; WITH SCL HIGH). 
EE_START:
	SETB	SDA	
	SETB	SCL			; SET BOTH BITS
	NOP				; DELAY
	CLR	SDA			; START CONDITION; SDA HI TO LOW TRANSITION
	NOP		
	NOP				; EEPROM ACCESS TIME DELAY
	CLR	SCL	
	CLR	C			; CLEAR ERROR FLAG
	RET				; ALL DONE
					; EE_STOP SENDS A STOP SEQUENCE TO THE EEPROM (LOW-TO-HIGH SDA TRANSITION 
					; WITH SCL HIGH).
EE_STOP:
	CLR	SDA	 
	NOP		
	NOP		
	SETB	SCL	
	NOP		
	NOP				; SETUP TIME DELAY
	SETB	SDA			; SEND A STOP CONDITION
	RET		
					; SHOUT SHIFTS DATA OUT TO THE EEPROM
SHOUT:
	PUSH	B	
 	MOV	B,#8			; SAVE B AND LOAD BIT COUNT

EEOUT:
	RLC	A			; SHIFT BIT LEFT (RLC=ROTATE LEFT THROUGH
					; CARRY)
	MOV	SDA,C			; GET DATA BIT FROM CARRY
	NOP		
	SETB	SCL			; CLOCK IN 1-BIT
	NOP				; CLOCK HIGH TIME
 	CLR	SCL			; CLOCK IS NOW LOW
	DJNZ	B,EEOUT			; DO IT 8 TIMES
	SETB	SDA			; RELEASE SDA FOR ACK
	NOP		
	NOP		
	SETB	SCL			; ACK CLOCK
	NOP		
	MOV	C,SDA			; GET THE ACK
	CLR	SCL			; CLEAR THE CLOCK BIT
	POP	B			; RESTORE WHATEVER B WAS
	RET		
					; SHIN SHIFT DATA IN FROM THE EEPROM
SHIN:	
	SETB	SDA			; MAKE SDA AN INPUT
	PUSH	B	
	MOV	B,#8 			; SAVE B AND SET BIT COUNTER

EEIN:
	NOP		
	SETB	SCL			; SET CLOCK
	NOP		
	NOP				; EEPROM ACCESS TIME
	SETB	SDA			; SET = 1 SO USED AS INPUT
	MOV	C,SDA			; READ 1-BIT
	RLC	A			; SHIFT BIT LEFT 
	CLR	SCL			; CLEAR CLOCK BIT
	DJNZ	B,EEIN			; GET NEXT BIT IF LESS THAN 8 BITS READ
	POP	B	
	RET		
					; ACK SENDS AN EEPROM ACKNOWLDEGE

ACK:
	CLR	SDA 	
	NOP		
	NOP		
	SETB	SCL			; CLOCK THE ACK
	NOP		
	CLR	SCL			; BRING CLOCK LOW
	RET		
					

NAK:					; NAK SENDS A NO ACKNOWLEDGE
	SETB	SDA	
	NOP		
	NOP		
	SETB	SCL			; CLOCK THE NAK
	NOP		
	CLR	SCL			; BRING CLOCK LOW
	RET
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top