Shop OBEX P1 Docs P2 Docs Learn Events
I2C help — Parallax Forums

I2C help

i2c_confusedi2c_confused Posts: 10
edited 2006-02-27 21:51 in BASIC Stamp
I am trying to communicate with an EEPROM chip (24FC515) using the bs2pe and it is not working.
The code I am using is as follows:

'{$STAMP BS2pe}
'{$PBASIC 2.5}
'{$PORT COM3}

sda PIN 0
current_ptr_b0 VAR Byte
address VAR Word
data_out VAR Byte
addr VAR Word


result VAR Byte

'The main loop

MainLoop:

GOSUB Init
GOSUB write_eeprom
GOSUB read_eeprom
DEBUG "Value read:",HEX result,CR
END


Init:

current_ptr_b0 = $00
data_out = $02
RETURN


write_eeprom:

I2COUT sda, $A0, current_ptr_b0, [noparse][[/noparse]HEX data_out]
DEBUG "writing Addr: ",HEX addr, " Value: ", HEX data_out, CR
PAUSE 2000
RETURN

read_eeprom:

I2CIN sda, $A1 , 0, [noparse][[/noparse]result]
DEBUG "reading Addr: ",HEX addr , " ", "Value: ", HEX result, CR
PAUSE 2000
RETURN


****************************************************************

The data that the stamp reads from the chip is always 1. I dont know why!

I am using 4.7k resistors and sda is connected to pin0.

Please help!

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-21 22:36
    i2c_confused -

    It appears from the data sheet that the ADDRESS must be 2 bytes (one WORD) in length. Thus, the ADDRESS in the I2Cxx commands will need to be specified in the "ADDRESS \ LOW ADDRESS" (separated bytes) format as shown in the PBASIC Help file, or the PBASIC Manual. In other words, something like this:

    curr_ptr_b0 VAR WORD

    I2COUT sda, $A0, curr_ptr_b0.highbyte\curr_ptr_b0.lowbyte, [noparse][[/noparse]HEX data_out]

    and

    I2CIN sda, $A1 , curr_ptr_b0.highbyte\curr_ptr_b0.lowbyte , [noparse][[/noparse]result]

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-22 01:17
    I've attached a file for you to try.··I don't have the part so I've not actually tested the program.· Please consult the data sheet for the 24LC515·for details.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-22 02:49
    Thank you for your help.

    I used the code (with modifications for the 24fc515 chip).

    I get a 'fail' output when I do this.

    Also: the output that the stamp reads is '1'.

    Any suggestions about what I might be doing wrong?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-22 03:46
    You'll have to work through it as you have the chip and I don't. The first step is to review the data sheet -- I may have missed something. I can try to pick up a chip at the electronics store tomorrow, but there's no guarantee they'll have one.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-22 06:32
    i2c_confused -

    Do you have the Stamp and EEPROM chip wired as follows:

    Stamp Pin Port 0 ==> SDA (EEPROM pin 5)
    Stamp Pin Port 1 ==> SCL (EEPROM pin 6)

    Vss (EEPROM pin 4) ==> Ground
    Vcc (EEPROM pin 8) ==> 2.5-5.5 VDC

    WP (EEPROM pin 7) tied to Vss
    A2 (EEPROM pin 3) tied to Vcc

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-22 15:25
    Thanks for your help. I checked the wiring and it still doesnt work.

    Could my stamp or eeprom be faulty?

    ·
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-22 15:47
    i2c_confused -

    My own guess would be the wiring or something external to the Stamp in some way is causing the problem, but that sounds terribly perjoritive - sorry. BTW - You get the continual 1's due to the required pull-up resistor I suspect.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-22 15:50
    It is not likely that eithe your Stamp or EEPROM is faulty. As difficult as it may be for you to believe, this issues are always tied back to a bad or incorrect connection. Check your wires to make sure something is not broken.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-24 20:26
    I ordered in a new EEPROM chip and it still doesnt work!

    I rewired everything- again, again and again.

    Could the fact that my eeprom chip operates at 1MHz be a problem? Its really fast.... which seems to be a good thing in most cases I thought.

    Any ideas about what I am doing wrong?

    The input and output pins on the stamp are working. I tested them with an oscilloscope and with leds.

    freaked.gif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-24 20:32
    Keep in mind that I2C is a syncronous buss and that 1 MHz number you're quoting is a maximum access speed. So... you've got a bad connection or bad code. Remember, the code I wrote was not tested by me; I wrote it for someone else who said that it worked fine. Once I get settled in my permanent home next week, I'll order a chip (couldn't find them locally) and test the code myself.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-24 21:13
    I am now testing my eeprom chip (sda and scl lines) using an oscilloscope.

    So, for a write command, I get the following waveform:

    1. Start bit. This is ok.

    2. Then, the slave id which is 10100000 for a write, this is ok too.

    3. Then,..... I need an ack bit. It is a low when the clock is high. BUT- I get a high when the clock is high. So my new eeprom chip is not sending an acknowledge bit. I have attached a waveform to show that.

    4. The next byte is a 00000000 for the high byte of the address... so the high that I am seeing could not be the next byte either.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-24 21:22
    You DO have a common ground between the BS2 and the EEPROM, right? It doesn't look like it from the o'scope display.
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-25 00:34
    My eeprom ground is connected to vss, which is the stamp ground as well.

    Post Edited (i2c_confused) : 2/25/2006 10:02:20 PM GMT
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-27 18:03
    So, I tried bit bashing and it works.

    Conclusion: The i2cin/out does not work. HIGH and LOW commands work! So, I used bit bashing instead.

    Here is an example of bit bashing that I modified to use:

    http://www.lennard.net.nz/electronics/i2c.html#eepromexample.

    Here is the waveform of the output using this code (see attached).

    For some reason, my stamp is not working properly.
    648 x 604 - 74K
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-27 19:38
    i2c_confused -

    Approximately how old is this BS-2p? There are I2C differences between the 1.3 (I think that's the version level) firmware and earlier firmware versions. I happen to have one of the eariler versions, which I keep meaning to have updated with the newer firmware.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • i2c_confusedi2c_confused Posts: 10
    edited 2006-02-27 21:51
    I have the new BS2-pe. I ordered it about a month ago.
Sign In or Register to comment.