Shop OBEX P1 Docs P2 Docs Learn Events
Newbie I2C EEPROM Question — Parallax Forums

Newbie I2C EEPROM Question

wbnwbn Posts: 29
edited 2005-08-02 20:42 in General Discussion
Am I safe in assuming that the SX/B I2C EEPROM example, I2C.SXB, will not work with a 4K x 8, 8K x 8, ... 24LC32, 24LC64, ... as the MEMIN/MEMOUT subroutines were written with the 8 x 256 x 8 24LC16 in mind? If so, would someone be so kind as to refer me to a version of the MEMIN/MEMOUT SX/B subroutines which would work in conjunction with an nK x 8 I2C EEPROM.

Thank you,

wbn

Comments

  • wbnwbn Posts: 29
    edited 2005-08-02 18:40
    Am I close?

    '
    ' Constants
    '


    SlaveID··CON·$A0

    Ack····· CON·0
    Nak····· CON·1


    '
    ' Subroutines Code
    '


    ' Use: MEMOUT addrLo, addrHi, aVal
    ' -- writes 'aVal' to 24LC16 at location addrHi/addrLo

    MEMOUT:
    · temp1 = __PARAM1
    · temp2 = __PARAM2
    · temp3 = __PARAM3

    · I2CSTART SDA
    ··temp4 = SlaveID·········· ' create control byte (with no chip select)
    '·temp4.0 = 0·············· ' set RW bit for write
    · I2CSEND SDA, temp4······ ·' send slave ID
    · I2CSEND SDA, temp2········' send word address
    · I2CSEND SDA, temp1······ ·' send word address
    · I2CSEND SDA, temp3······ ·' send data byte
    · I2CSTOP SDA·············· ' finish
    · RETURN


    ' Use: MEMIN addrLo, addrHi, @aVal
    ' -- reads 'aVal' from 24LCXX with·XXK x 8·bits at location addrHi/addrLo

    MEMIN:
    · temp1 = __PARAM1
    · temp2 = __PARAM2
    · temp3 = __PARAM3

    · I2CSTART SDA
    · temp4 = SlaveID····· ···· ' create control byte (with no chip select)
    '·temp4.0 = 0·············· ' set RW bit for write
    · I2CSEND SDA, temp4······· ' send slave ID
    · I2CSEND SDA, temp2······· ' send address high byte
    · I2CSEND SDA, temp1······· ' send address low byte
    · I2CSTART SDA
    · temp4.0 = 1············· ·' set RW bit for read
    · I2CSEND SDA, temp4······· ' resend slave ID
    · I2CRECV SDA, temp4, Nak···' get one byte
    · I2CSTOP SDA
    · __RAM(temp3) = temp4····· ' move to target RAM
    · RETURN
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-02 20:42
    There is no generic routine for a nKx8 I2C memory -- the trouble is that each device has different addressing schemes and you'll have to tailor the subroutines above to the target device. I've written a lot of I2C code for the BASIC Stamp so I've been through this. If you've got a specific device in mind I can help you adjust the code.

    Another thing to keep in mind is that as of version 1.3, SX/B·subroutines can return a value so you don't have to pass address parameters anymore. This simplifies code and eliminates one temporary variable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.