PDA

View Full Version : I2CREAD and I2CWRITE problems



yourmomOS
- 5th April 2006, 05:01
All,
I am having real problems with an i2c eeprom. I have read the datasheet and can not find the answer I am looking for. I am using a 16f628 and a 24LC512. I can not seem to get any real data from the eeprom. I have both clock and data pulled high with 4.7k. Here is just one of the code samples I have tried. On this one I finally was just trying to write a simple letter into the eeprom. I tried number, letters, variables. All I am getting on the screen is a smiley face!? Can someone help please?

define OSC 20
CMCON = 7 'TURN OFF COMPARATOR
'Include "modedefs.bas" ' Include serial modes

SO con 0 ' Define serial output pin
DPIN var PORTA.0 ' I2C data pin
CPIN var PORTA.1 ' I2C clock pin
B0 var word
B1 var byte
symbol control = %11010000


For B0 = 0 To 15
B1 = B0 ' Loop 16 times
I2CWRITE DPIN,CPIN, control,$A0,B0,["B"] ' Write each location's address to itself
Pause 10 ' Delay 10ms after each write
Next B0
SEROUT2 PORTB.2, 84,["WRITE COMPLETED", 10, 13]
loop: For B0 = 0 To 15 step 2 ' Loop 8 times
I2CREAD DPIN,CPIN, control, $A0,B0,[B1] ' Read 2 locations in a row
pause 10
serout2 PORTB.2, 84,[B1]
Next B0

serout2 PORTB.2, 84, [10, 13]


Goto loop

Melanie
- 5th April 2006, 09:58
http://www.picbasic.co.uk/forum/showthread.php?t=587