I2C help
i2c_confused
Posts: 10
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!
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
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 Williams
Applications Engineer, Parallax
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 Williams
Applications Engineer, Parallax
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 -->
Could my stamp or eeprom be faulty?
·
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 Williams
Applications Engineer, Parallax
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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.
Post Edited (i2c_confused) : 2/25/2006 10:02:20 PM GMT
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.
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 -->