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] Writing To EEPROM AT24c512 using AT89s52

Status
Not open for further replies.

muyalrabbit

Newbie level 5
Newbie level 5
Joined
Sep 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
Hi Fallowing Is My Code To Write Value 2 At Address 0x08 Of
EEProm AT24C512 Using AT89s52.
The Code Executes And No Value Is Written On ROM
Help Me Debug This.


;CODE FOR AT89S52
;EEPROM AT24C512
;WRITING VALUE 2 AT EEPROMS 0X08
;
ORG 0H
VRBLS: ;VARIABLES
SCL EQU P2.0 ;I2C CLOCK
SDA EQU P2.1 ;I2C DATA
I2CDAT EQU 28H ;I2C DATA VARIABLE
SJMP START ;GOTO START
;I2C MODULE START
I2CSTART: ;I2C START
SETB SDA
SETB SCL
NOP
NOP
CLR SDA
NOP
NOP
CLR SCL
RET
I2CSTOP: ;I2C STOP
CLR SDA
SETB SCL
NOP
NOP
SETB SDA
NOP
NOP
RET
I2CWRBT: ;I2C WRITE A BYTE
CLR SCL ;I2C CLOCK LOW
MOV SDA,47H ;SENDING MSB OF I2CDATA
ACALL I2CCLK ;I2C CLOCK
MOV SDA,46H ;SENDING NEXT BIT OF I2CDATA
ACALL I2CCLK
MOV SDA,45H
ACALL I2CCLK
MOV SDA,44H
ACALL I2CCLK
MOV SDA,43H
ACALL I2CCLK
MOV SDA,42H
ACALL I2CCLK
MOV SDA,41H
ACALL I2CCLK
MOV SDA,40H ;SENDING LSB OF I2CDATA
ACALL I2CCLK ;12C CLOCK
RET
I2CCLK: ;I2C CLOCK
SETB SCL
NOP
NOP
CLR SCL
NOP
NOP
RET
I2CACK: ;I2C ACKNOWLEDGE
CLR SCL
SETB SCL
NOP
JNB SDA,I2CAKD
CLR SCL
RET
I2CAKD:
CLR SCL
RET
;I2C MODULE END
;EEPROM MODULE START
EEWRADD: ;EEPROM ADDRESS WITH WRITE ENABLE
MOV I2CDAT,#0A6H ;SEND DEVICE ADDRESS + ENABLE WRITE
ACALL I2CWRBT
ACALL I2CACK
RET
EERDADD: ;EEPROM ADDRESS WITH READ ENABLE
MOV I2CDAT,#0A7H ;SEND DEVICE ADDRESS + ENABLE WRITE
ACALL I2CWRBT
ACALL I2CACK
RET
;EEPROM MODULE END
START:
ACALL I2CSTART ;I2C START
ACALL EEWRADD ;I2C WRITE DEVICE ADDRESS WITH WRITE OPTION
MOV I2CDAT,#0H ;I2C EEPROM ADDRESS LOCATION (1ST BYTE)
ACALL I2CWRBT ;I2C WRITE
ACALL I2CACK ;I2C ACKNOWLEDGE
MOV I2CDAT,#08H ;12C EEPROM ADDRESS LOCATION (2nd BYTE)
ACALL I2CWRBT ;I2C WRITE
ACALL I2CACK ;I2C ACKNOWLEDGE
MOV I2CDAT,#02H ;WRITE VALUE 2 TO EEPROM
ACALL I2CWRBT ;I2C WRITE
ACALL I2CACK ;I2C ACKNOWLEGE
ACALL I2CSTOP ;I2C STOP
HERE: SJMP HERE ;STAY HERE
END
 

muyalrabbit

Newbie level 5
Newbie level 5
Joined
Sep 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
Code File Is Attached In Text Format For Readability
 

Attachments

  • I2C.txt
    1.8 KB · Views: 44

kirangowle

Member level 3
Member level 3
Joined
Apr 6, 2010
Messages
65
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Bangalore
Activity points
1,632
You are checking on hardware or in simulation?
I am poor at assembly language.
 

amol_shah

Full Member level 3
Full Member level 3
Joined
Apr 21, 2008
Messages
151
Helped
31
Reputation
62
Reaction score
15
Trophy points
1,298
Location
Nasik
Activity points
2,034
Are you using pullup resistors for the SCL & SDA lines? Increase the delay just two nop instructions will not work.
 

muyalrabbit

Newbie level 5
Newbie level 5
Joined
Sep 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
@Kirangowle
Iam using Proteus 7 Simulator

---------- Post added at 15:09 ---------- Previous post was at 14:59 ----------

@Amol_Shah
Iam Using Port2 (Pins 2.0 & 2.1). They Do Have Inbuild Pullup resistors are they not enough ?
Advice Me.
I am using Proteus 7 and viewing I2c memory module window in debug mode.
Memory Location Is Not Updated (I2C Rom Memory Location 0008 Value = FF instead of 02)
 

FvM

Super Moderator
Staff member
Advanced Member level 7
Joined
Jan 22, 2008
Messages
50,988
Helped
14,630
Reputation
29,536
Reaction score
13,739
Trophy points
1,393
Location
Bochum, Germany
Activity points
291,730
I don't understand what you're doing here. What's send to SDA (P2.1)?

Code:
I2CWRBT:          ;I2C WRITE A BYTE
   CLR SCL            ;I2C CLOCK LOW
   MOV SDA,47H    ;SENDING MSB OF I2CDATA
   ACALL I2CCLK    ;I2C CLOCK
   MOV SDA,46H    ;SENDING NEXT BIT OF I2CDATA
   ACALL I2CCLK
   MOV SDA,45H
   ACALL I2CCLK
   MOV SDA,44H
   ACALL I2CCLK
   MOV SDA,43H
   ACALL I2CCLK
   MOV SDA,42H
   ACALL I2CCLK
   MOV SDA,41H
   ACALL I2CCLK
   MOV SDA,40H    ;SENDING LSB OF I2CDATA
   ACALL I2CCLK      ;12C CLOCK
   RET
 

amol_shah

Full Member level 3
Full Member level 3
Joined
Apr 21, 2008
Messages
151
Helped
31
Reputation
62
Reaction score
15
Trophy points
1,298
Location
Nasik
Activity points
2,034
Internal pull ups are not sufficient for high speed communication. Increase the delay and use pullups of 2.2k.
MOV SDA,41H?? If i am not wrong you cannot move bit data from one bit location to another directly.
do this:
MOV C,47H
MOV SDA,C
 

muyalrabbit

Newbie level 5
Newbie level 5
Joined
Sep 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
@FVM
47h = MSB bit Address of 28h. We store the value in 28h and MOV to SDA bit by bit

---------- Post added at 16:01 ---------- Previous post was at 15:54 ----------

@Amol_Shah
I Guess Bit Mov Works
Any How Now I Asaigned Those Locations as B0-B7.
And Changed The Code as MOV SDA,B0
Assembler Failed To Assemble So I Change The Code As u Advised
Now Code Is Like Below
MOV C,B0
MOV SDA,C

Thank You
 

FvM

Super Moderator
Staff member
Advanced Member level 7
Joined
Jan 22, 2008
Messages
50,988
Helped
14,630
Reputation
29,536
Reaction score
13,739
Trophy points
1,393
Location
Bochum, Germany
Activity points
291,730
do this:
MOV C,47H
MOV SDA,C
Yes, I'm not aware of a bit to bit MOV instruction of 8051. The original instruction is misunderstood as a MOV direct, direct byte move.

RLC A would be more economic method to output the bits.
 

muyalrabbit

Newbie level 5
Newbie level 5
Joined
Sep 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
Proteus File And Code Attached
 

Attachments

  • EEProm.zip
    14.7 KB · Views: 79
  • I2C.txt
    3.5 KB · Views: 34
  • I2C.txt
    1.8 KB · Views: 32

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top