Need help to get I2CRead woriking


Results 1 to 4 of 4

Threaded View

  1. #1
    w7ami's Avatar
    w7ami Guest

    Angry Need help to get I2CRead woriking

    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
    Attached Images Attached Images  
    Last edited by w7ami; - 28th November 2007 at 23:19. Reason: Correct typo and add file

Similar Threads

  1. I2CRead and USART interrupt
    By HenrikBuhl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th January 2007, 13:04
  2. I2cwrite - I2cread
    By savnik in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th July 2006, 01:12
  3. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th June 2006, 20:03
  4. Problem with I2Cread and I2CWRITE function
    By Tony85 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th June 2006, 18:32
  5. PFC8583 Connection and I2Cwrite I2cread!
    By uludere72 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 27th February 2006, 13:32

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts