interfacing AT24c256

Discussion in 'Embedded Systems and Microcontrollers' started by alagu222, May 17, 2008.

  1. alagu222

    Thread Starter New Member

    May 17, 2008
    2
    0
    hi
    i am trying to interface AT24c256 with AT89c51. i am not able to do this sucessfully. i have used the code (attached). the problem is i am not getting the ack from the chip back.

    thanks in advance
     
  2. alagu222

    Thread Starter New Member

    May 17, 2008
    2
    0
    sorry the program is


    MOV DPTR,#125H
    MOV DYTA,#79H
    LCALL EEPROM_WRITE ;IN ADDRESS 125H DATA IS 79H
    MOV DPTR,#125H
    LCALL EEPROM_READ
    MOV A,DYTA ;NOW ACC IS 79H


    SDA EQU P2.6
    SCL EQU P2.7
    DYTA EQU 50H
    ADRES EQU 51H

    I2C_READ: ;reading 8 bits from i2c device
    MOV R7,#8
    GFD:
    SETB SDA
    SETB SCL
    MOV C,SDA
    RLC A
    CLR SCL
    DJNZ R7,GFD
    MOV DYTA,A
    RET
    I2C_WRITE: ;writing 8 bits in to i2c device
    MOV R7,#8
    WRITING:
    RLC A
    MOV SDA,C
    LCALL CLOCK
    DJNZ R7,WRITING
    RET
    I2C_START: ;start of i2c routine
    SETB SCL
    SETB SDA
    CLR SDA
    CLR SCL
    RET
    I2C_STOP: ;end of i2c routine
    SETB SCL
    CLR SDA
    SETB SDA
    CLR SCL
    RET
    CLOCK: ;synchronizing clock
    SETB SCL
    CLR SCL
    RET

    ACK: ;acknowledge from transmitter or receiver
    SETB SDA
    SETB SCL
    JB SDA,$
    CLR SCL
    RET
    NO_ACK: ;no acknowledge from transmitter or receiver
    SETB SDA
    CLR SCL
    JNB SDA,$
    SETB SCL
    RET

    ;*************************
    ;SERIAL EEPROM PACKAGE****
    ;*************************
    EEPROM_WRITE: ;write in to eeprom
    LCALL I2C_START
    LCALL EEPROM_WRITE_ADDR
    LCALL ACK
    MOV A,DPH
    LCALL I2C_WRITE
    LCALL ACK
    MOV A,DPL
    LCALL I2C_WRITE
    LCALL ACK
    MOV A,DYTA
    LCALL I2C_WRITE
    LCALL ACK
    LCALL I2C_STOP
    LCALL DELAY_STOP
    RET
    EEPROM_READ: ;read from eeprom
    LCALL I2C_START
    LCALL EEPROM_WRITE_ADDR
    LCALL ACK
    MOV A,DPH
    LCALL I2C_WRITE
    LCALL ACK
    MOV A,DPL
    LCALL I2C_WRITE
    LCALL ACK
    LCALL I2C_START
    LCALL EEPROM_READ_ADDR
    LCALL ACK
    LCALL I2C_READ
    LCALL NO_ACK
    LCALL I2C_STOP
    RET
    EEPROM_READ_ADDR: ;A2,A1,A0 are zero
    MOV A,#10100001B
    LCALL I2C_WRITE
    RET
    EEPROM_WRITE_ADDR: ;A2,A1,A0 are zero
    MOV A,#10100000B
    LCALL I2C_WRITE
    RET
    DELAY_STOP: ;terminating write process
    MOV TMOD,#00000001B
    MOV TH0,#0EEH
    MOV TL0,#00H
    SETB TR0
    SAC:
    JNB TF0,SAC
    CLR TR0
    CLR TF0
    RET
     
Loading...