Shop OBEX P1 Docs P2 Docs Learn Events
24LC128 memory chip problem — Parallax Forums

24LC128 memory chip problem

guru1guru1 Posts: 8
edited 2007-05-12 04:13 in BASIC Stamp
I recently bought the 24LC128 memory chip to interface with my BS2P24. I tried the following code to verify whether it works.
SDA··········· PIN····· 0············· ' I2C Serial Data Line
SCL··········· PIN····· 1············ ' I2C Serial Clock Line
val VAR Byte
val=$8
· 'Writing secion
· I2COUT SDA, $A0,12, [noparse][[/noparse]val]
· PAUSE 200
··' Reading Section
· I2CIN SDA, $A1,12, [noparse][[/noparse]val]
· DEBUG CR, "Value stored is ", HEX val, CR
I keep getting "FF" as the result no matter what value I put fro "val". I'm sure of all my connection are correct. Any help will be greatly appreciated. Thanks in advance

Post Edited (guru1) : 5/12/2007 3:45:15 AM GMT

Comments

  • Desy2820Desy2820 Posts: 138
    edited 2007-05-12 02:41
    You probably already have this covered, but did you add the two·pull-up resistors between·SDA and SCL and the positive voltage rail?· You need seperate resistors for each pin.

    Also, not a code expert, but are you waiting the required time after a write before trying to read the value?· The writes on the chip takes a few milliseconds.·

    Maybe run the write part before the read part?· It looks like your code reads the previous value, then writes a new one.

    I also take it that you manually change the constant "val" to get different values?

    I hope this helps!






    Post Edited (Desy2820) : 5/12/2007 2:49:10 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-12 02:55
    For reading, you have to use the I2CIN statement and for writing, you have to use the I2COUT statement.
    Since EEPROMs expect a 16 bit address, you have to use the high\low address format. As Desy2820 mentioned,
    you must have the pull-up resistors shown in the PBasic manual and you have to wait at least 20ms after a write
    before doing anything else with the EEPROM (read or write).

    With the larger EEPROMs, you include the high order bits of the EEPROM address as part of the "slave ID".
    You should read the datasheet for the EEPROM device for specifics. That will also discuss "page mode".
  • guru1guru1 Posts: 8
    edited 2007-05-12 04:13
    I made a mistake when making my comments: the "writing section" should be the "reading section" instead and vice versa. I've corrected it.
    It's working like magic now. Thanks for all your help.
Sign In or Register to comment.