I know that there been many questions about i2c, but i have problem and can't solve it without help - sample code for reading/writing to eeprom doesn't work for me:
SO con 0 ' Define serial output pin
DPIN var PORTD.4 ' I2C data pin
CPIN var PORTD.3 ' I2C clock pin
B0 var byte
B1 var byte
B2 var byte
For B0 = 0 To 15 ' Loop 16 times
I2CWRITE DPIN,CPIN,$A0,B0,[B0] ' Write each location's address to itself
Pause 10 ' Delay 10ms after each write
Next B0
Loop: For B0 = 0 To 15 Step 2 ' Loop 8 times
I2CREAD DPIN,CPIN,$A0,B0,[B1,B2] ' Read 2 locations in a row
Serout SO, N2400, [#B1," ",#B2," "] ' Print 2 locations
Next B0
Serout SO, N2400, [10] ' Print linefeed
Goto loop
All I get is bunch of "255", which is wrong value. It seems neither writing or reading work. I tried with pull-ups on SDA, SCL (tried 10K and 4.7K) and no change. Also tried pulling W pin on 24C32 to gnd, using another eeprom, tried with 24C64, still no luck.I'm using 16F877A on 20MHz and PBP 2.42 version.
What should I try next?
Bookmarks