Shop OBEX P1 Docs P2 Docs Learn Events
Connecting and code for 4KB EEPROM 24LC32A - Page 2 — Parallax Forums

Connecting and code for 4KB EEPROM 24LC32A

2»

Comments

  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-30 02:48
    yes i can run that code

    Main:
    DEBUG "Test",cr
    end

    If you can run the above code you know that your programming / debug connection is OK.
    (It must be since you loaded it into the processor!)

    So you concern about “cabling” is solved.

    You did say that you get no display running the EEPROM code.
    You should be able to "step " thru the EEPROM code and let us know where it is falling.
    Follow the flow and add DEBUG(s) to verify the flow.
    You need to establish that before you start troubleshooting the EEPROM.
    It is not necessary to obtain correct debug printouts, you are not after the values of the variables, just verifying the flow.

    I would recommend you do that and than post your code again with some comments how far you have gotten.

    And yes, at present only the I2C I/O pins need pull-ups.
  • dev/nulldev/null Posts: 381
    edited 2009-09-30 08:15
    umm. This EEPROM is a serial device, not I2C. Or did I miss something.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-30 11:50
    /dev/null just said...
    umm. This EEPROM is a serial device, not I2C. Or did I miss something.
    umm, well, I asked, umm, for clarification and
    chris jones said...
    this is the EEPROM that i am trying to use

    4KB EEPROM 24LC32A

    i am sorry about any mixup but the subject of the post is 4KB EEPROM 24LC32A
    and an, umm,·24LC32 , is, umm, an I2C, umm, device

    umm, so, you did, umm, miss, umm,·something

    Y/N ?
  • chris joneschris jones Posts: 391
    edited 2009-09-30 12:42
    Hello

    i have an update on my device

    Also here is what i get what the samle program that was given
    800 x 600 - 150K
    589 x 384 - 32K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-30 13:19
    It's very blurry, but it·looks like you have the resistors going in series·between SDA, SCL and·P0, P1.· If that's so then you need to take a closer look at the schematic.
  • chris joneschris jones Posts: 391
    edited 2009-09-30 14:28
    i have a resistor going to SCL to P0 and SDL to P1 the only thing i can think of is that both pins need to be connected to ground as well.
  • ZootZoot Posts: 2,227
    edited 2009-09-30 14:36
    Chris, there is nothing to "think" about, and my fear is you are just trying things randomly without a clear picture of where you are going.

    Go look at the schematic that dev/null posted. It is correct. If you don't know how to read a schematic, then check out any of the nice micro books by Parallax (available for download) which explain how to read a schematic.

    In short, you need a wire between P0 and SDA, and between P1 and SCL. You *also* need a 4.7k (or so) resistor between P0 and +5v and also between P1 and +5v. These are called "pull-ups", because they "pull" the level of the signal on that wire to a logic 1 if the wire is not being driven to logic 0 by the Stamp or by the EEPROM.

    Get your circuit right first. Then try the code. If that doesn't work, then post your FULL PROGRAM that failed (as an attachment, not pasted into the message), along with a picture showing that your circuit is correct, and we can take it from there.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-30 14:46
    Chris,
    you are on the right track with software debbuging.
    You got pass this line :
    DEBUG "i2cdata at ", DEC wrdAddr, " = ", DEC i2cdata, CR

    END

    Now continue to follow the flow and insert DEBUGs whereever it will help you to see how far you can get in the flow.
    Here is a sample :



    '
    [noparse][[/noparse] Subroutines ]
    '
    [noparse][[/noparse] "Macros" ]
    ' For Writing
    Write_op:
    DEBUG "Write_op Sub", CR
    slvAddr.BIT1 = wrdAddr.BIT8 ' set page bit
    DEBUG ? slvAddr.BIT1,CR
    GOSUB Write_Byte

    PAUSE 10
    RETURN


    As I said before it is not necessary to see correct values( but it helps) , you are after the flow of the code for now.
  • chris joneschris jones Posts: 391
    edited 2009-10-01 04:16
    Hello i have updated my wirehookup can anyone verify to let me know if this is correct
    600 x 800 - 132K
    589 x 384 - 32K
  • chris joneschris jones Posts: 391
    edited 2009-10-01 04:26
    just an update this is the program that i am working with now Pj Allen posted a rar with this file in it

    ' =========================================================================
    '
    '·· File....... 24LC32.BS2
    '·· Purpose.... 24LC32 demo with a BS2/BS2e/BS2sx
    '·· Author..... Jon Williams, Parallax
    '·· E-mail.....
    jwilliams@parallax.com
    '·· Started....
    '·· Updated.... 07 SEP 2004
    '
    '·· {$STAMP BS2}
    '·· {$PBASIC 2.5}
    '
    ' =========================================================================


    '
    [noparse][[/noparse] Program Description ]


    '
    [noparse][[/noparse] Revision History ]


    '
    [noparse][[/noparse] I/O Definitions ]

    SDA············ PIN···· 0······················ ' I2C serial data line
    SCL············ PIN···· 1······················ ' I2C serial clock line


    '
    [noparse][[/noparse] Constants ]

    Ack············ CON···· 0······················ ' acknowledge bit
    Nak············ CON···· 1······················ ' no ack bit

    EE24LC32······· CON···· %1010 << 4

    '
    [noparse][[/noparse] Variables ]

    slvAddr········ VAR···· Byte··················· ' I2C slave address
    devNum········· VAR···· Nib···················· ' device number (0 - 7)
    addrLen········ VAR···· Nib···················· ' bytes in word addr (0 - 2)
    wrdAddr········ VAR···· Word··················· ' word address

    i2cData········ VAR···· Byte··················· ' data to/from device
    i2cWork········ VAR···· Byte··················· ' work byte for TX routine
    i2cAck········· VAR···· Bit···················· ' Ack bit from device

    test··········· VAR···· Nib
    outVal········· VAR···· Byte
    inVal·········· VAR···· Byte
    fails·········· VAR···· Word


    '
    [noparse][[/noparse] EEPROM Data ]


    '
    [noparse][[/noparse] Initialization ]

    Check_Module:
    · #IF ($STAMP >= BS2P) #THEN
    ··· #ERROR "Use I2COUT and I2CIN!"
    · #ENDIF

    Setup:
    · devNum = %000································ ' chip select (%000 - %111)
    · slvAddr = EE24LC32 | (devNum << 1)··········· ' setup slave ID
    · addrLen = 2·································· ' 2 bytes in word address

    · DEBUG CLS
    · DEBUG "24LC32 Demo··· ", CR,
    ······· "

    ", CR,
    ······· "Address...···· ", CR,
    ······· "Output....···· ", CR,
    ······· "Input.....···· ", CR,
    ······· "Status....···· ", CR,
    ······· "Errors....···· "

    '
    [noparse][[/noparse] Program Code ]

    Main:
    · fails = 0
    · FOR wrdAddr = 0 TO 4095······················ ' test all locations
    ··· DEBUG CRSRXY, 11, 2, DEC4 wrdAddr
    ··· FOR test = 0 TO 3·························· ' use four patterns
    ····· LOOKUP test, [noparse][[/noparse]$FF, $AA, $55, $00], outVal
    ····· DEBUG CRSRXY, 11, 3, IHEX2 outVal
    ····· i2cData = outVal
    ····· GOSUB Write_Byte
    ····· PAUSE 10
    ····· GOSUB Read_Byte
    ····· inVal = i2cData
    ····· DEBUG CRSRXY, 11, 4, IHEX2 inVal,
    ··········· CRSRXY, 11, 5
    ····· IF (inVal = outVal) THEN
    ······· DEBUG "Pass "
    ····· ELSE
    ······· fails = fails + 1
    ······· DEBUG "Fail ", CRSRXY, 11, 6, DEC fails
    ······· EXIT··································· ' terminate location
    ····· ENDIF
    ····· PAUSE 10
    ··· NEXT
    · NEXT
    · IF (fails = 0) THEN
    ··· DEBUG CRSRXY, 11, 6, "None. All locations test good."
    · ENDIF
    · END


    '
    [noparse][[/noparse] Subroutines ]



    ' =====[noparse][[/noparse] High Level I2C Subroutines]=======================================
    ' Random location write
    ' -- pass device slave address in "slvAddr"
    ' -- pass bytes in word address (0, 1 or 2) in "addrLen"
    ' -- word address to write passed in "wrdAddr"
    ' -- data byte to be written is passed in "i2cData"

    Write_Byte:
    · GOSUB I2C_Start······························ ' send Start
    · i2cWork = slvAddr & %11111110················ ' send slave ID (write)
    · GOSUB I2C_TX_Byte
    · IF (i2cAck = Nak) THEN Write_Byte············ ' wait until not busy
    · IF (addrLen > 0) THEN
    ··· IF (addrLen = 2) THEN
    ····· i2cWork = wrdAddr.BYTE1·················· ' send word address (1)
    ····· GOSUB I2C_TX_Byte
    ··· ENDIF
    ··· i2cWork = wrdAddr.BYTE0···················· ' send word address (0)
    ··· GOSUB I2C_TX_Byte
    · ENDIF
    · i2cWork = i2cData···························· ' send data
    · GOSUB I2C_TX_Byte
    · GOSUB I2C_Stop
    · RETURN


    ' Random location read
    ' -- pass device slave address in "slvAddr"
    ' -- pass bytes in word address (0, 1 or 2) in "addrLen"
    ' -- word address to write passed in "wrdAddr"
    ' -- data byte read is returned in "i2cData"

    Read_Byte:
    · GOSUB I2C_Start······························ ' send Start
    · IF (addrLen > 0) THEN
    ··· i2cWork = slvAddr & %11111110·············· ' send slave ID (write)
    ··· GOSUB I2C_TX_Byte
    ··· IF (i2cAck = Nak) THEN Read_Byte··········· ' wait until not busy
    ··· IF (addrLen = 2) THEN
    ····· i2cWork = wrdAddr.BYTE1·················· ' send word address (1)
    ····· GOSUB I2C_TX_Byte
    ··· ENDIF
    ··· i2cWork = wrdAddr.BYTE0···················· ' send word address (0)
    ··· GOSUB I2C_TX_Byte
    ··· GOSUB I2C_Start
    · ENDIF
    · i2cWork = slvAddr | %00000001················ ' send slave ID (read)
    · GOSUB I2C_TX_Byte
    · GOSUB I2C_RX_Byte_Nak
    · GOSUB I2C_Stop
    · i2cData = i2cWork
    · RETURN


    '
    [noparse][[/noparse] Low Level I2C Subroutines ]

    ' *** Start Sequence ***
    I2C_Start:····································· ' I2C start bit sequence
    · INPUT SDA
    · INPUT SCL
    · LOW SDA

    Clock_Hold:
    · DO : LOOP UNTIL (SCL = 1)···················· ' wait for clock release
    · RETURN


    ' *** Transmit Byte ***
    I2C_TX_Byte:
    · SHIFTOUT SDA, SCL, MSBFIRST, [noparse][[/noparse]i2cWork\8]····· ' send byte to device
    · SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1]········· ' get acknowledge bit
    · RETURN


    ' *** Receive Byte ***
    I2C_RX_Byte_Nak:
    · i2cAck = Nak································· ' no Ack = high
    · GOTO I2C_RX

    I2C_RX_Byte:
    · i2cAck = Ack································· ' Ack = low

    I2C_RX:
    · SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cWork\8]········ ' get byte from device
    · SHIFTOUT SDA, SCL, LSBFIRST, [noparse][[/noparse]i2cAck\1]······ ' send ack or nak
    · RETURN


    ' *** Stop Sequence ***
    I2C_Stop:······································ ' I2C stop bit sequence
    · LOW SDA
    · INPUT SCL
    · INPUT SDA
    · RETURN
  • ZootZoot Posts: 2,227
    edited 2009-10-01 05:07
    No, your circuit is not correct. You should not have resistors as the connection between your two pins and SDA and SCL on the EEPROM. You should have wires. AND you need resistors from the pins to Vdd (+5v). See my previous posts. And PJ Allen's. And dev/null's. Look over the schematic.

    If that code is Jon's original demo without changes, and you are indeed using a 32kbit EEPROM (4k bytes) then the code is probably fine. Should work. The circuit errors may be what are causing the program to hang, as the I2C lines may not get released properly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • chris joneschris jones Posts: 391
    edited 2009-10-01 12:52
    You guys are awesome i have the chip working.sorry for my lack of knowlege in things but i am still learning and someday i may be as smart as you guys.

    AWESOMENES!!!!!!

    how do i close this thread

    Thanks
    PJ Allen
    dev/null
    Zoot
    vaclav_sal
Sign In or Register to comment.