Shop OBEX P1 Docs P2 Docs Learn Events
basic stamp 2p40 cannot read 24lc128 eeprom chip.. help!! — Parallax Forums

basic stamp 2p40 cannot read 24lc128 eeprom chip.. help!!

PHM102PHM102 Posts: 27
edited 2006-12-08 01:36 in BASIC Stamp
we have troubleshoot the circuit of the 24lc128 for several times... we have even change the 24lc128 chip.. however, it still not working when·running the demo·program·(I2CIN·and I2COUT)...· can someone provide help in this? could it be bs2p40 faulty?

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-02 05:10
    Hello,
    ·
    ·· Do you have the 4.7K resistors on the SDA/SCL lines?· What do you mean it’s not working?· What exactly is happening?· Do you have code you can post?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • PHM102PHM102 Posts: 27
    edited 2006-12-02 06:09
    Chris Savage (Parallax) said...
    Hello,
    ·
    ·· Do you have the 4.7K resistors on the SDA/SCL lines?· What do you mean it’s not working?· What exactly is happening?· Do you have code you can post?

    Yup we did have the resistors connected correctly. We follow exactly what the Basic Stamp book show us. We used the sample program that·is included in the basic stamp program (I2C.BSP). The error that we got was the Basic Stamp is having trouble to read in from the EEPROM (Which I believe there is a problem writing too). In the debug screen, the error prompt out as "Error: expected ... ... ..."

    anyway this is the program,

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}

    #IF ($STAMP < BS2P) #THEN
    · #ERROR "Program requires BS2p, BS2pe, or BS2px."
    #ENDIF

    SDA············ PIN···· 0·············· ' I2C SDA pin
    SCL············ PIN···· SDA + 1

    addr··········· VAR···· Word··········· ' internal address
    block·········· VAR···· Nib············ ' block address in 24LC16
    value·········· VAR···· Byte··········· ' value to write
    check·········· VAR···· Nib············ ' for checking retuned values
    result········· VAR···· Byte(16)······· ' array for returned value


    Write_To_EEPROM:
    · DEBUG "Writing...", CR
    · PAUSE 2000
    · FOR addr = 0 TO 2047 STEP 16········· ' loop through all addresses
    ··· block = addr.NIB2 << 1············· ' calculate block address
    ··· value = addr >> 4·················· ' create value from upper 8 bits
    ··· ' write 16 bytes
    ··· I2COUT SDA, $A0 | block, addr, [noparse][[/noparse]REP value\16]
    ··· PAUSE 5
    ··· DEBUG "Addr: ", DEC4 addr, "-", DEC4 addr + 15, "· ",
    ········· "Value: ", DEC3 value, CR
    · NEXT
    · PAUSE 2000

    Read_From_EEPROM:
    · DEBUG CR, "Reading...", CR
    · PAUSE· 2000
    · FOR addr = 0 TO 2047 STEP 16
    ··· block = addr.NIB2 << 1
    ··· value = addr >> 4
    ··· I2CIN SDA, $A1 | block, addr, [noparse][[/noparse]STR result\16]
    ··· FOR check = 0 TO 15
    ····· IF (result(check) <> value) THEN Error
    ··· NEXT
    ··· DEBUG "Addr: ", DEC4 addr, "-", DEC4 addr + 15, "· ",
    ········· "Value: ", DEC3 result, CR
    · NEXT
    · PAUSE 100
    · DEBUG CR, "All locations passed"
    · END


    Error:
    · DEBUG "Error at location: ", DEC4 addr + check, CR,
    ······· "Found: ", DEC3 result(check), ", Expected: ", DEC3 value
    · END
  • RandyRandy Posts: 79
    edited 2006-12-02 17:24
    I had a similar problem with the 24LC128. I don't remember how or why but I found if I use a 47K resistor on the SCL and a 4.7 k on the SDA it works fine. I have tried going back to the 4.7k resistors later thinking maybe it was something else that I missed or just a flaky connection but it won't work with 4.7k on the clock line. I hope this helps and more so does anyone have a reason? I don't remember what they were but all of the voltage, resistance readings were as expected.

    Randy
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-04 00:44
    Hello,
    ·
    ·· Since the code you posted appears to be for the 24LC16, please try the code for the 24LC128 posted at the following link and see if that works for you.· Be sure you set the I/O lines in the code the same as you’re using…Take care.

    http://www.parallax.com/detail.asp?product_id=602-00013

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • PHM102PHM102 Posts: 27
    edited 2006-12-05 02:09
    thanks for the wonderful reply... we will try out later

    EDIT: Tried the sample program and it works but would like to ask what does the "eeprom_add.HIGHBYTE\eeprom_add.LOWBYTE" does?

    Post Edited (PHM102) : 12/5/2006 6:48:31 AM GMT
  • PHM102PHM102 Posts: 27
    edited 2006-12-06 08:04
    Can i just put "eeprom_add" instead of the above?

    edit;

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    SDA··········· PIN····· 0············· ' I2C Serial Data Line
    SCL··········· PIN····· 1············· ' I2C Serial Clock Line
    ee_addr··· VAR··· Word
    value····· VAR··· Word
    ee_addr = $50
    I2COUT SDA,$A0,ee_addr.HIGHBYTE\ee_addr.LOWBYTE, [noparse][[/noparse]200]
    I2CIN SDA, $A1,ee_addr.HIGHbyte\ee_addr.LOWBYTE, [noparse][[/noparse]value]
    ·DEBUG DEC value

    i am trying to store a value of 200 to address $50 then read out the value from address $50. However it came out 255 instead of 200. urgent help is needed. thanks

    Post Edited (PHM102) : 12/6/2006 8:57:30 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-06 15:18
    Hello,
    ·
    ·· Did the program I referred you to work as it is for you?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • RandyRandy Posts: 79
    edited 2006-12-07 02:46
    I2C protocal sends information as bytes. There are start, stop and acknowledge signals with the data (bytes) in between. You can send a word value as two bytes, the highbyte and the lowbyte. But if you try to send it as a word, only half of it will be sent (the high byte). There needs to be an ACK signal before the next byte can be sent. The second half of the word (the low byte) is not saved anywhere waiting to be sent, it is simply lost. You can pour two liters of water into a one liter bottle but you are only going to have one liter of water. The other liter will be on the ground - lost! Use two bottles, high liter and low liter. If you have the BASIC Stamp Syntax and Reference Manual it gives an explanation of how I2C works.

    Randy
  • PHM102PHM102 Posts: 27
    edited 2006-12-07 08:21
    ya we referred to the manual but still quite blur at it. Yes the program that Chris gave is working thanks. Hmm... if thats the case, why in the manual they can just use the command e.g. I2COUT SDA,$A0,0, [noparse][[/noparse]value]? Please pardon me for my ignorance and thanks in advance...
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-07 17:29
    Hello,
    ·
    ·· Please see Randy’s reply above…If you’re trying to store values greater than 255 then you need to store two bytes and move two address positions for each write.· Is this where you’re having trouble?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • PHM102PHM102 Posts: 27
    edited 2006-12-08 01:36
    Hi there, thanks for the prompt reply... Ah I see... thanks greatly for the enlightenment shocked.gif
Sign In or Register to comment.