Shop OBEX P1 Docs P2 Docs Learn Events
Stamp Interface with external eeprom — Parallax Forums

Stamp Interface with external eeprom

ArchiverArchiver Posts: 46,084
edited 2002-12-03 01:22 in General Discussion
I am going crazy tring to figure out how to get my BS2SX to
interface with a microchip 24LC64 EEPROM. I found the following
code for the 24LC32 (which is the same only 32K less) however when I
download the program and run it, it seems to get caught in an
infinite loop because of the statment ' if ack=1 then agn ' can
someone please help me out with this. Possibly an incorrect wiring
job on my part?? I dont know?!? Please Help! Thanks :-)

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-12-02 22:49
    --- In basicstamps@y..., "jasonsch312" <schuler_jason@h...> wrote:
    > I am going crazy tring to figure out how to get my BS2SX to
    > interface with a microchip 24LC64 EEPROM. I found the following
    > code for the 24LC32 (which is the same only 32K less) however when
    I
    > download the program and run it, it seems to get caught in an
    > infinite loop because of the statment ' if ack=1 then agn ' can
    > someone please help me out with this. Possibly an incorrect
    wiring
    > job on my part?? I dont know?!? Please Help! Thanks :-)

    oops forgot to add the code! Duh!
    '{$STAMP BS2sx}
    ' 24LC32.BS2
    '
    ' Illustrates how to write and read to and from 24LC32 32K EEPROM
    '
    ' BS2 24LC32
    '
    ' Pin5 (term 10)
    SCL (term 6)
    To Other
    ' Pin4 (term 9)
    SDA (term 5)
    24LC32
    Devices
    '
    ' Note that 10K pullup resistors to +5VDC are required on both signal
    'leads.
    '
    ' Note that the slave address is determined by A2 (term 3), A1
    (term2)
    ' and A0 (term 1) on 24LC32. The above SCL and SDA leads may be
    multipled
    ' to eight devices, each strapped for a unique A2 A1 A0 setting.
    '
    ' Debug and Pause statements were included only to see what is going
    on.
    '

    address var word ' 000 0000 00000 - 111 1111 1111
    device var byte ' device 0-7
    dta var byte ' data to program

    o_byte var byte ' byte to send to memory
    i_byte var byte ' byte fetched from memory

    n var byte ' index
    b var bit ' bit
    ack_bit var bit

    SDA_PIN con 4
    SCL_PIN con 5
    SDA_OUT var out4
    SCL_OUT var out5
    SDA_IN var in4
    SDA_DIR var dir4

    OUT con 1
    IN con 0

    dirs=$f0ff

    main
    address=$341 ' program data 55 into address $341
    device=0
    dta=$55

    gosub write_random_data 'write dta to address $341

    gosub read_random_data 'read from same location
    debug hex i_byte

    stop

    write_random_data 'writes specified data to specified address
    agn

    gosub start

    o_byte=$a0 | (device << 1) ' 1 0 1 0 a2 a1 a0 0
    gosub out_byte
    gosub nack
    o_byte= address >> 8 ' high byte of address
    gosub out_byte
    gosub nack
    o_byte= address & $ff ' low byte of address
    gosub out_byte
    gosub nack
    o_byte= dta ' data
    gosub out_byte
    gosub nack

    gosub sstop

    gosub ack ' ack polling
    if ack_bit=1 then agn
    return

    read_random_data ' reads data from specified address
    ' returns in variable in_byte

    gosub start
    o_byte=$a0 | (device << 1) ' 1 0 1 0 a2 a1 a0 0
    gosub out_byte
    gosub nack
    o_byte= address >> 8 ' high byte of address
    gosub out_byte
    gosub nack
    o_byte= address & $ff ' low byte of address
    gosub out_byte
    gosub nack

    gosub start
    o_byte=$a0 | (device << 1) | $01' 1010 a2 a1 a0 1
    gosub out_byte
    gosub nack

    gosub get_byte
    gosub nack

    gosub sstop
    return

    out_byte

    low SDA_PIN

    for n=0 to 7
    b= (o_byte >> 7) & 1
    if (b=1) then out_one
    SDA_DIR=OUT
    debug "0"
    _clk
    high SCL_PIN
    pause 100
    low SCL_PIN
    pause 100
    o_byte=o_byte << 1
    next
    SDA_DIR=IN
    return
    out_one
    SDA_DIR=IN
    debug "I"
    goto _clk


    get_byte
    SDA_DIR=IN 'input

    i_byte=0
    for n=0 to 7
    pause 200
    high SCL_PIN
    pause 200
    i_byte=(i_byte << 1) | SDA_IN
    debug dec SDA_IN
    low SCL_PIN

    next

    SDA_DIR=OUT 'output
    return

    nack
    SDA_DIR=IN ' input just in case
    ack_bit=1
    high SCL_PIN
    ack_bit=SDA_IN
    debug "A"
    debug dec ack_bit
    debug $0d
    low SCL_PIN
    SDA_DIR=OUT ' output
    return

    ack

    debug "POLL"
    gosub start
    o_byte=$a0 | (device << 1)
    gosub out_byte
    gosub nack

    return

    start
    high SDA_PIN
    high SCL_PIN
    debug "START"
    debug $0d
    low SDA_PIN 'bring SDA low while clock is high
    low SCL_PIN
    return

    sstop
    low SDA_PIN
    high SCL_PIN
    pause 10
    high SDA_PIN 'bring SDA high while clock is high
    debug "STOP"
    debug $0d
    return
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-02 23:55
    --- In basicstamps@y..., "jasonsch312" <schuler_jason@h...> wrote:
    > I am going crazy tring to figure out how to get my BS2SX to
    > interface with a microchip 24LC64 EEPROM. I found the following
    > code for the 24LC32 (which is the same only 32K less) however when
    I
    > download the program and run it, it seems to get caught in an
    > infinite loop because of the statment ' if ack=1 then agn ' can
    > someone please help me out with this. Possibly an incorrect
    wiring
    > job on my part?? I dont know?!? Please Help! Thanks :-)


    Hey I dont know if anybody is interested but I found the information
    to get the eeprom to work. Here is the website which explains the
    process really well. Anywho... Happy Stamping!

    http://www.gorobotics.net/i2ceeprom.shtml
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-03 00:07
    At 10:49 PM 12/2/02 +0000, you wrote:
    >--- In basicstamps@y..., "jasonsch312" <schuler_jason@h...> wrote:
    > > I am going crazy tring to figure out how to get my BS2SX to
    > > interface with a microchip 24LC64 EEPROM. I found the following
    > > code for the 24LC32 (which is the same only 32K less) however when
    >I
    > > download the program and run it, it seems to get caught in an
    > > infinite loop because of the statment ' if ack=1 then agn ' can
    > > someone please help me out with this. Possibly an incorrect
    >wiring
    > > job on my part?? I dont know?!? Please Help! Thanks :-)
    You may want to check with Prof. Peter Anderson since he's the one who holds
    the copyright on the program. I suspect he'd appreciate having the copyright
    notice replaced in the program: http://www.phanderson.com/stamp/i2c/24lc32.html

    Regards,

    Bruce Bates
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-03 01:22
    One of my "Stamp Applications" columns for Nuts & Volts this year was called
    "I2C Fun For Everyone." You can download the column in PDF form from:

    http://www.parallax.com/html_pages/resources/nvcolumns/Nuts_Volts_Downloads_V3

    .asp

    There's probably something in the article and code examples that will help
    you out.

    -- Jon Williams
    -- Parallax


    In a message dated 12/2/02 4:47:53 PM Central Standard Time,
    schuler_jason@h... writes:


    > I am going crazy tring to figure out how to get my BS2SX to
    > interface with a microchip 24LC64 EEPROM. I found the following
    > code for the 24LC32 (which is the same only 32K less) however when I
    > download the program and run it, it seems to get caught in an
    > infinite loop because of the statment ' if ack=1 then agn ' can
    > someone please help me out with this. Possibly an incorrect wiring
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.