+ Post New Thread
Results 1 to 13 of 13
  1. #1
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Writing To EEPROM AT24c512 using AT89s52

    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

  2. #2
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Re: Writing To EEPROM AT24c512 using AT89s52

    Code File Is Attached In Text Format For Readability



  3. #3
    Member level 3
    Points: 1,646, Level: 9
    Achievements:
    7 years registered

    Join Date
    Apr 2010
    Location
    Bangalore
    Posts
    65
    Helped
    3 / 3
    Points
    1,646
    Level
    9

    Re: Writing To EEPROM AT24c512 using AT89s52




    •   AltAdvertisement

        
       

  4. #4
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Re: Writing To EEPROM AT24c512 using AT89s52

    Help Me To Find The Problem In My Code



  5. #5
    Member level 3
    Points: 1,646, Level: 9
    Achievements:
    7 years registered

    Join Date
    Apr 2010
    Location
    Bangalore
    Posts
    65
    Helped
    3 / 3
    Points
    1,646
    Level
    9

    Re: Writing To EEPROM AT24c512 using AT89s52

    You are checking on hardware or in simulation?
    I am poor at assembly language.



  6. #6
    Full Member level 3
    Points: 2,965, Level: 12
    Achievements:
    7 years registered
    amol_shah's Avatar
    Join Date
    Apr 2008
    Location
    Nasik
    Posts
    153
    Helped
    32 / 32
    Points
    2,965
    Level
    12

    Re: Writing To EEPROM AT24c512 using AT89s52

    Are you using pullup resistors for the SCL & SDA lines? Increase the delay just two nop instructions will not work.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  7. #7
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Re: Writing To EEPROM AT24c512 using AT89s52

    @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)



  8. #8
    Super Moderator
    Points: 264,204, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,168
    Helped
    14041 / 14041
    Points
    264,204
    Level
    100

    Re: Writing To EEPROM AT24c512 using AT89s52

    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



  9. #9
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Re: Writing To EEPROM AT24c512 using AT89s52

    Yes

    p2.0 = SCL
    P2.1 = SDA



  10. #10
    Full Member level 3
    Points: 2,965, Level: 12
    Achievements:
    7 years registered
    amol_shah's Avatar
    Join Date
    Apr 2008
    Location
    Nasik
    Posts
    153
    Helped
    32 / 32
    Points
    2,965
    Level
    12

    Re: Writing To EEPROM AT24c512 using AT89s52

    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


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  11. #11
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Re: Writing To EEPROM AT24c512 using AT89s52

    @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



  12. #12
    Super Moderator
    Points: 264,204, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,168
    Helped
    14041 / 14041
    Points
    264,204
    Level
    100

    Re: Writing To EEPROM AT24c512 using AT89s52

    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.


    1 members found this post helpful.

  13. #13
    Newbie level 5
    Points: 271, Level: 3

    Join Date
    Sep 2011
    Posts
    9
    Helped
    0 / 0
    Points
    271
    Level
    3

    Re: Writing To EEPROM AT24c512 using AT89s52

    Proteus File And Code Attached



--[[ ]]--