I need help getting I2CRead to work. I am using an 18F4620 running at 4 MHz and a 24LC65 serial eeprom. I can write data to the eeprom but I can not read the data back out. I have an oscilloscope connected to the clock and data lines of the eeprom and I can see that it is sending data back to the pic. The data bus is two way and I can see both the data sent to and from the eeprom, see the attached file. The returned value of Data1 is always 0. What the hey?
; PIC18F4620
DEFINE OSC 4
;**************************************
; *** LCD SET UP ***
;
;Set up LCD display ports
DEFINE LCD_DREG PORTC ; Set LCD Data Port to port C
DEFINE LCD_DBIT 0 ; Fisrt data port is C.0
DEFINE LCD_RSREG PORTC ; Register Select Port is C
DEFINE LCD_RSBIT 4 ; Register Select Bit is 4
DEFINE LCD_EREG PORTC ; Set LCD Enable Port is C;
DEFINE LCD_EBIT 5 ; Set LCD Enable Bit is 5
DEFINE LCD_BITS 4 ; 4 bus lines
DEFINE LCD_LINES 4 ; 4 display lines
DEFINE LCD_COMMANDUS 2000 ; command delay in uS
DEFINE LCD_DATUS 50 ; Set data delay in uS
;
; ** Define LCD Control Constants **
I CON $fe ; Instruction Prefix
CLR CON $1 ; Clear the display
L1 CON $80 ; Line 1
L2 CON $C0 ; line 2
L3 CON $94 ; Line 3
L4 CON $D4 ; Line 4
;
;**************************************
;
; I2C Setup
;
SDA VAR PORTE.1 ; I2C data pin
SLC VAR PORTE.0 ; I2C clock pin
I2CAddress VAR WORD
I2CDevice VAR BYTE
Data1 VAR BYTE
;
I2CDevice = $A0
;
;**************************************
PAUSE 1000 ; Wait for LCD to initialize
LCDOUT I, CLR ; Clear LCD
PAUSE 1000
LCDOUT i, l4, "Ready"
; Write Pattern To eeprom
For I2CAddress = 0 To 20 STEP 2 ; Loop 10 times
I2CWRITE SDA,SLC,I2CDevice,I2CAddress,[%10101010, %01010101]
LCDOUT I, L1, DEC I2CAddress
Pause 10 ; Delay 10 mS after each write
Next
Loop:
For I2CAddress = 0 To 20 ; Loop 20 times
I2CREAD SDA,SLC,I2CDevice,I2CAddress,[Data1], BadRead
LCDOUT I, L2 ,DEC I2CAddress, " ", DEC Data1
PAUSE 500
NEXT
GOTO Loop
BadRead:
LCDOUT I, L3 , "Bad Read"
GOTO Loop
end
Bookmarks