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

Connecting and code for 4KB EEPROM 24LC32A

chris joneschris jones Posts: 391
edited 2009-10-01 12:52 in BASIC Stamp
Hello

i have a basic stamp 2 board of education and i was needing help connecting the chip and some simple code to read and write to the chip.
«1

Comments

  • chris joneschris jones Posts: 391
    edited 2009-09-28 20:56
    here is a sample program but it still does not show that my eeprom is working


    ' {$STAMP BS2}
    'Code by Shaun Wilson November 01/99
    'This is code writes data reads data to 25LC640 64K EEPROM and
    'displays it in the debug screen. It will give you in idea of
    'how to read and write data to the EEPROM. To use it in your
    'specific app just insert the subroutines into you code


    '
    Constants
    WRSR_EERPOM CON $01 'write status register
    WRITE_EEPROM CON $02 'write data to memory beginning at selected address
    READ_EEPROM CON $03 'read data from memory beginning at selected adress
    WRDI_EEPROM CON $04 'Reset the write enable latch
    RDSR_EEPROM CON $05 'read status register
    WREN_EEPROM CON $06 'set the write enable latch

    Serdata CON 2 'serial data in/out
    SerClk CON 1 'Serial clock input

    '
    Varibles

    EEPROM_data VAR Byte 'data
    Status_register VAR Byte 'read status byte
    EEPROM_busy VAR Status_register.LOWBIT 'first bit of the read status
    address VAR Word '

    '
    Program

    address = 0 'address to start writing data to
    EEPROM_data = $AA 'data to write to EEPROM

    main:
    DEBUG " Writing ", HEX EEPROM_data, " to location ",HEX address DIG 3,HEX address DIG 2, HEX address DIG 1, HEX address DIG 0, " of the EEPROM", CR
    GOSUB writeEEPROM 'subroutine to write data to EEPROM
    IF address > 20 THEN readEEPROM 'only right to the first 20 locations
    address=address+1 'counter to increment the memory address
    GOTO main

    '
    Subroutines


    WriteEEPROM:
    GOSUB EEPROMreadstatus 'check to see if the EEPROM is busy
    IF EEPROM_Busy =1 THEN WriteEEPROM 'if its busy loop until its not

    SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]WREN_EEPROM] 'tell the EEPROM you want to
    'set the write enable latch

    'Tell the EEPROM you want to write to it, send the 16bit address to write to,
    'and send a byte of data to write to that location
    SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]Write_EEPROM,Address\16,EEPROM_data\8]

    RETURN

    EEPROMreadstatus:

    'send the command to EEPROM that a device wants to read the status register
    SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]RDSR_EEPROM]
    'return the byte containing the status of the read register
    SHIFTIN SerData,SerClk,MSBPRE,[noparse][[/noparse]Status_register\8]
    EEPROM_busy = Status_register

    RETURN

    ReadEEPROM:
    address =0 'set address back to 0
    PAUSE 10
    FOR address = 0 TO 30 'read 30 locations of the EEPROM

    'send command to EEPROM that a device wants to read data from a memory location
    SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]READ_EEPROM,Address\16]
    'returns a byte of data from the EEPROM
    SHIFTIN SerData,SerClk,MSBPRE,[noparse][[/noparse]EEPROM_data\8]

    DEBUG " The data in location ", HEX address DIG 3,HEX address DIG 2, HEX address DIG 1, HEX address DIG 0, " of the EEPROM is ",HEX EEPROM_data, CR
    NEXT
    GOSUB done
    RETURN

    done:
    DEBUG " Done "
    PAUSE 1000
    GOTO done
  • chris joneschris jones Posts: 391
    edited 2009-09-28 21:00
    ok still have tehy same issue but changed a few lines for the pins

    Serdata CON 1 'serial data in/out
    SerClk CON 2 'Serial clock input
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-28 22:36
    http://www.chip-review.com/download/21223e.pdf
    Here is the link to the datasheet. Read it first.
    Your code has Serdata for both input and output.
    This EEPROM has separate signals·for input and output.
    Aslo make sure all you other (EEPROM)·pins are properly conected and your timing is correct also.


    Minor addition - if your code "reads EEPROM status" ( and yours at present time·cannot·for the above reason) you should add a DEBUG command and "print it out". That way you know for sure what the hardware is doing.




    Post Edited (vaclav_sal) : 9/28/2009 10:44:42 PM GMT
  • chris joneschris jones Posts: 391
    edited 2009-09-28 22:43
    the datasheet you listed is diffrent from the datasheet with the product
    24LC32A
  • chris joneschris jones Posts: 391
    edited 2009-09-28 22:46
    also the exmalpe listed above is something i gou online i just changed my pins i have worked on this for 1 week and looked at the datasheet over and over and still can not get it to work.

    ALSO note this is the link that a parallax tech gave me and whats listed with the chip
    http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/24LC32A.pdf
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-28 22:50
    But the code is written for 25LC640, then check out 24LC32 datasheet.
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-28 23:00
    OK the data signal on 24LC32A is both input and output. However, your code does not have any configuration code. You need to set the address ( both hardware and software) and write protect.
    Check out another thread here - it has some hardware info in it.
    The key here is - you are dealing with two different devices and need to have correct hardware setup before you start coding.
    It will save you time in the long run and you will avoid lots of frustration and disappointments.


    PS I think ( but I may be confused with another chip) you can set all of the address pins to OPEN, thus saving some pesky wiring, and have the corresponding address scheme. ·But I am not sure, check it in the spec sheet first.
    Never mind - I was wrong. You need to connect the address pins.
    Up to eight devices may be connected to the same bus
    by using different Chip Select bit combinations. These
    inputs must be connected to either VCC or VSS.

    Post Edited (vaclav_sal) : 9/28/2009 11:16:03 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-28 23:06
    I modified Jon Williams's Demo which writes and reads all the addresses, but mine just works it as needed (specific addresses.)

    [noparse][[/noparse] I love 'magic numbers.' ]

    SDA is P0, SCL is P1 and the device's chip_select number·should be configured as '00'.
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-28 23:20
    PJ - very nice coding style. Very clean, maybe I have learn something today! Cudos. Atta boy.

    PS My C code is always full of "MN's "!
  • chris joneschris jones Posts: 391
    edited 2009-09-28 23:38
    Hello PJ Allen

    i get a blank screen when i run this program is there something i need to add
  • chris joneschris jones Posts: 391
    edited 2009-09-29 00:03
    Hello


    the only thing i can think of isd that my cables are hooked in wrong does anyone have a basic stamp homework board that a screenshot can be taken and posted.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-29 00:39
    Cables, what cables?

    Nothing has to be added.

    The program posted uses DEBUGs.· If your BoE programs OK, then why won't the DEBUGs go?· You may need to make sure that your DEBUG window COM Port is appropriate.
  • chris joneschris jones Posts: 391
    edited 2009-09-29 04:15
    can you explain this "DEBUG window COM Port is appropriate" i have used debug statements in other programs and it works but do i have to setup the comm a diff way for this exmaple?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-29 12:01
    The COM Port being used is in the upper-left of the DEBUG window.· Some people have more than one COM Port available, etc., so it needs to match the one you're plugged into.

    I didn't write the program on the fly, untested; it works.· My suggestion is that you strategically place some DEBUG statements within the program [noparse][[/noparse]e.g.·from the top·-- DEBUG "Starting...", CR ] so that you can monitor its progress and determine where you're cratering.

    Check your wiring, re-check it, and then check it again.
  • chris joneschris jones Posts: 391
    edited 2009-09-29 12:04
    Hello



    i have been up all night beating myself up on this issue i have rewired the board about 100 times i think and still nothing.I also uncommented some debug statements befor the sub calls and it displays text in the debug window.
  • chris joneschris jones Posts: 391
    edited 2009-09-29 15:55
    i took off work today to test this agian and i still have a blank debug window. Do you think i have a bad set of chips, i have tried it on 3 of my boards and i have tried all 3 EEPROM chips.
  • dev/nulldev/null Posts: 381
    edited 2009-09-29 17:27
    Just for the record:

    attachment.php?attachmentid=64080

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
    548 x 434 - 19K
  • chris joneschris jones Posts: 391
    edited 2009-09-29 17:28
    I have seen this setup and followed it still no go
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-29 20:53
    References to 25LC640 (an SPI device), 24LC32 (an I2C device)... what's the deal?
    Which EEPROM are you trying to use?


    ·
  • chris joneschris jones Posts: 391
    edited 2009-09-29 20:57
    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
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-29 21:03
    Here are the I2C resources links --

    http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol5/col/nv115.pdf

    http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol5/code/nv115.zip

    The zip has a 24C32 demo.· If it won't go, I cannot help further.
  • chris joneschris jones Posts: 391
    edited 2009-09-29 21:08
    Thanks PJ Allen for all of your help you have given me a helping hand in my issue. I will see if anyone has the board to show a snapshot of the wirehookup and go from there. I am thinking that the basic stamp or the eeprom is not the best for my project.


    Thanks Agian
    Chris Jones
  • dev/nulldev/null Posts: 381
    edited 2009-09-29 21:25
    The first project I did with an EEPROM was with 24LC128, just because it was well documented by Parallax. And it worked right away. You might consider using this one instead of 24LC32A. Wiring and code is in the PDF on the product page.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-09-29 21:26
    " i took off work today to test this agian and i still have a blank debug window."

    Can you run this "program"?


    Main:
    DEBUG "Test",cr
    end
  • chris joneschris jones Posts: 391
    edited 2009-09-29 21:42
    yes· i can run that code

    Main:
    DEBUG "Test",cr
    end
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-30 00:30
    chris,

    How about you take a good picture of your set-up and post that?· A blurry photo or one lacking detail won't help, but anyway.

    This isn't rocket science and it's not about a "bad batch" of "chips."· Something·is missing·or·there's some other mistake.
  • chris joneschris jones Posts: 391
    edited 2009-09-30 01:43
    ok i have the pictures i tried to take 2 good shots of what my hookup is

    i hope this helpssmile.gif
    800 x 600 - 135K
    800 x 600 - 160K
  • ZootZoot Posts: 2,227
    edited 2009-09-30 01:56
    Where are your pullup resistors? I don't see them in your photo. I2C will not work w/o the pullups. See dev/null's schematic in the middle of the first page of this forum topic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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-09-30 02:30
    do i need to hook resistors for each ground or just the IO pins P0 and P1
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-09-30 02:32
    One goes from SDA to V_dd and one goes from SCL to V_dd (not "Ground".)
Sign In or Register to comment.