i2cRead i2cwrite very frustrating


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    13

    Default i2cRead i2cwrite very frustrating

    I had a program I wrote w/ PBP2.5 using a PIC 18F4550, everything worked great. I am ditching USB and going zigbee, so I'm changing from the 18F4450 to an PIC18F46K22. In the process I have also upgraded to PBP3.

    This code from PBP2.5 on an 18F4450 works flawlessly:
    Code:
    Define  OSC     48
    C0B0W CON %10100000 'Chip 0, Bank 0, Write
    C0B1W CON %10101000 'Chip 0, Bank 1, Write
    C0B0R CON %10100001 'Chip 0, Bank 0, Read
    C0B1R CON %10101001 'Chip 0, Bank 1, Read
    DEFINE I2C_SLOW 1   'have to use slow for the i2c LCD
    I2CLCD CON 80
    SDA VAR  PORTB.0
    SCL VAR  PORTB.1
    I2CADDRESS VAR  WORD
    SECONDS  VAR WORD
    i2CTEST  VAR BYTE[8]
    TESTLCD  VAR BYTE[8]
    Main:
    I2CADDRESS = 0
    I2CWRITE SDA,SCL,C0B0W,I2CADDRESS,[65,66,67,68,69,70,71,72,73]
    pause 50
    i2cread SDA,SCL,C0B0R,I2CADDRESS,[STR I2CTEST\8]
    pause 50
    HSEROUT ["<TEST>", STR I2CTEST\8,  "</TEST>"]    
     
    Seconds = Seconds + 1
    arraywrite TestLCD ,[DEC4 Seconds]
    I2CWRITE SDA,SCL,I2CLCD,[$FE,$45,$40,STR TestLCD\4]
    Goto Main

    This code, on the 18f46k22 does NOT work. I can write the to I2C LCD, but I can NOT read/write to the i2c eeproms.
    Code:
    Define  OSC     64  
    C0B0W CON %10100000 'Chip 0, Bank 0, Write
    C0B1W CON %10101000 'Chip 0, Bank 1, Write
    C0B0R CON %10100001 'Chip 0, Bank 0, Read
    C0B1R CON %10101001 'Chip 0, Bank 1, Read
    DEFINE I2C_SLOW 1   'have to use slow for the i2c LCD
    I2CLCD CON 80
    SDA VAR  PORTC.4
    SCL VAR  PORTC.3
    I2CADDRESS VAR  WORD
    SECONDS  VAR WORD
    i2CTEST  VAR BYTE[8]
    TESTLCD  VAR BYTE[8]
    Main:
    I2CADDRESS = 0
    I2CWRITE SDA,SCL,C0B0W,I2CADDRESS,[65,66,67,68,69,70,71,72,73]
    pause 50
    i2cread SDA,SCL,C0B0R,I2CADDRESS,[STR I2CTEST\8]
    pause 50
    HSEROUT ["<TEST>", STR I2CTEST\8,  "</TEST>"]    
     
    Seconds = Seconds + 1
    arraywrite TestLCD ,[DEC4 Seconds]
    I2CWRITE SDA,SCL,I2CLCD,[$FE,$45,$40,STR TestLCD\4]
    Goto Main
    I have 3 bread boards.
    Breadboard 1 has an 18f4550 and all the related hardware specific to make the chip run.
    Breadboard 2 has an 18F46k22 and all the related hardware specific to make the chip run.
    Breadboard 3 has all my I2c eeproms and LCDs connected to it, so I can move it between breadboard 1 and 2.

    The only difference between breadboard 1 and 2 as far as the I2C goes, the ports for SDA/SLC are different on the chips.

    Both Setups work to the LCD via i2c. Both chips count up and display correctly to the LCD correctly, so I know I2C is working.

    Only the 18F4550 Reads and writes to the eeprom. I get <TEST>ABCDEFGH</TEST> back via the serial line on the 18F4550.

    On the 18F46K22 I get <TEST>........</TEST> (the .'s are hex 00)

    The Eeprom is 24FC1025.

    I have tried to isolate this as much as possible, but I'm lost. Any clue? Is something different on PBP3 vs PBP2.5 as far as I2C?

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: i2cRead i2cwrite very frustrating

    Bradb, I beleive you have to pass the constant "C0B0W" to a variable to have it work as the last bit will be changed whether it is a Write or a Read instruction. At least that is the way I have used it in the past 3 years and on all of my products that use the 24LC1025's. I have never had a problem with them and, infact are using 2 of them w/18F26K22 for my newest project.
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Aug 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: i2cRead i2cwrite very frustrating

    Dave,
    Agreed about the last bit, but I'm using 2 different constants, C0B0W and C0B0R (chip0 bank0, read or write) to address the last bit issue.

    So that's not it....

  4. #4
    Join Date
    Aug 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: i2cRead i2cwrite very frustrating

    I found it...
    I was missing...

    ANSELC.3 = 0
    ANSELC.4 = 0

    I had moved to port D during my testing, so actually mine was
    ANSELD.0 = 0
    ANSELD.1 = 0

    Why doesn't I2CWRITE and I2CREAD auto set these like it does for SERIN and SEROUT??? Or At least mention that it needs done in the manual. 7 hours of my life I'll never get back. (I'll also never forget ANSEL needs set on a I2C!!)

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: i2cRead i2cwrite very frustrating

    Bradb, Good to hear you got it working. I didn't see the port config bit's in your code snipit so I assumed you had everything set correctly.
    Dave Purola,
    N8NTA
    EN82fn

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