I2C issue w/ 18F6722


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156

    Default I2C issue w/ 18F6722

    I have not used a PIC18F6722 before, but needed two UART PORTS so decided to give it a try. I did not expect to have I2C issues, but when I try to do a read (of a PCF8574) using I2C port 1 it always returns DEC 16. When troubleshooting this, I pulled all the PCF8574's from their sockets, and also removed an EEPROM from the buss. Now the buss is empty except for two pullup 4.7K pullup resistors. It STILL returns DEC 16! I carefully examined the traces on the board, and they are clean and not tied to anything they shouldn't be. I also tried the same code on the second I2C port (which also has nothing on it but pullups) and it has the decency to return 0. To me that means that it's probably some conflict on port C, or other configuration error that I'm not aware of, or possibly a compiler error (2.60 Patch A).

    Can anybody spot what I'm doing wrong?

    Thanks,
    Len

    Code:
    'PIC18F6722
    
    ASM
        CLRF PORTC      
        MOVLW 10000000b                          ;SET PIN DIRECTION 
        MOVWF TRISC 
     
        CLRF PORTD      
        MOVLW 00000010b                          ;SET PIN DIRECTION 
        MOVWF TRISC 
    ENDASM
     
    DEFINE OSC 20                                'XTAL FREQUENCY
    
    'DEBUG PORT 
    DEFINE DEBUG_REG PORTD                       'DEBUG PINS ARE IN PORTD                               
    DEFINE DEBUG_BIT 0                           'TRANSMIT DEBUG PIN IS PORTD.0
    DEFINE DEBUG_BAUD 115200                     '115200 BAUD                             
    DEFINE DEBUG_MODE 0                          'NO INVERSION
    DEFINE DEBUGIN_BIT 1                         'RECEIVE DEBUG PIN IS PORTD.1
    
    X    VAR  BYTE
    
    TEST:       
    I2CREAD PORTC.4,PORTC.3,%01000001,[X]         'DOESN'T WORK - ALWAYS RETURNS DEC 16
    'I2CREAD PORTD.5,PORTD.6,%01000001,[X]        'WORKS
    DEBUG BIN8 X,10,13
    PAUSE 500
    GOTO TEST
    Last edited by circuitpro; - 15th July 2010 at 23:16. Reason: typo

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Try changing your TRIS registers.

    It looks like you have them set to outputs both clk and data.

    Not sure why you are using asm?
    and you set trisc two time I think you wanted to set port D in the second statement

    Try (without asm)
    PORTC = 0 ; clear portc
    TRISC =%0001000 ;set portc.4 to input all others outputs
    PORTD = 0 ;clear port d
    TRISD =%0010000 ;set portd.5 to input all others outputs

    This matches your IC2READ statements , if you want to use other pins you need to change
    the DATA and clock pin assignments

    TEST:
    I2CREAD PORTC.4,PORTC.3,%01000001,[X] 'DOESN'T WORK - ALWAYS RETURNS DEC 16
    'I2CREAD PORTD.5,PORTD.6,%01000001,[X] 'WORKS
    DEBUG BIN8 X,10,13
    PAUSE 500
    GOTO TEST


    Regards
    Last edited by mark_s; - 16th July 2010 at 00:23.

  3. #3
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Unhappy

    No difference. It is behaving the same way

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by circuitpro View Post
    No difference. It is behaving the same way

    Do you have a schematic? Which pins on the pic go to which pins on PCF chip?


    Take a look in the manual under I2CREAD, you have to set your datapin and clockpin to match
    the physical connection to the pic. Also TRIS must be set to match.

  5. #5
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    After reading thru the datasheet section on the MSSP modules, I'm sure it's my error in not setting something in the MSSP up properly. I will have to get down and really figure out what all these setup bits actually do when I get back in front of hardware later today. My first post was a little misleading by saying the second I2C port 'worked'. It returned '0', but there wasn't any hardware on the buss either. It also did not work with hardware on the buss. It just kept returning '0's. That points away from hardware (I've used this PCF8574's for years, and the hardware is connected right). It's the dummy driving the new PIC that's at fault. :-(
    Last edited by circuitpro; - 16th July 2010 at 18:44. Reason: additional

  6. #6
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Smile

    Code:
    SSP1CON1.5=1                                 'ENABLE I2C #1
    SSP1CON1.3=1                                 'SET I2C#1 FOR MASTER MODE
    SSP1CON1.2=0                                 'SET I2C#1 FOR MASTER MODE
    SSP1CON1.1=0                                 'SET I2C#1 FOR MASTER MODE
    SSP1CON1.0=0                                 'SET I2C#1 FOR MASTER MODE
    fixed my problem. Apparently the PBP I2C command doesn't do any setting of this stuff for hardware I2C pins, so must be set.

    Thanks for your help Mark.

    Len

Members who have read this thread : 0

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