PIC18F14K50 and i2cread/i2cwrite on PORT C


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Posts
    57

    Default PIC18F14K50 and i2cread/i2cwrite on PORT C

    I am trying to use i2cread and i2cwrite on a PIC18F14K50.
    PORTC.6 = Clock, PORTC.7 = Data.
    Of course I know that there is an issue with the comparator/analog in settings.
    So I am using:

    ANSEL = 0
    ANSELH = 0

    to configure PORTC for digital I/O.
    But i get the impression that this is not good enough...
    When I measure the voltage on the clock pin (C6), it is low but can easily be pulled high with a resistor connected between PORTC.6 and +5V, giving me the impression that this pin is not configured as a digital output.
    Am I still missing something?
    (I prefer PORTC.6 and PORTC.7 because this would make the PCB design easier...)

  2. #2
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: PIC18F14K50 and i2cread/i2cwrite on PORT C

    Mmm... To eliminate things, I tried to use i2cread/i2cwrite on PORTB.4 (Clock) and PORTB.5 (Data), but this also doesn't seem to work.
    TRISB=0 sets the outputs to a solid low level, but the I2C commands are still not working.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: PIC18F14K50 and i2cread/i2cwrite on PORT C

    You need those pull-up resistors on both pins for I2C.
    2.2 or 4.7K.
    DT

  4. #4
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: PIC18F14K50 and i2cread/i2cwrite on PORT C

    Quote Originally Posted by Darrel Taylor View Post
    You need those pull-up resistors on both pins for I2C.
    2.2 or 4.7K.
    Yes, I know that this is an often made mistake.
    But of course I have those pull-up resistors connected!
    The strange thing is that everything worked fine with a PIC18F4550, but not with a PIC 18F14K50.
    When I look with an oscilloscope on the data and clock lines, I don't see any signal at all while sending an I2C command.
    Last edited by RuudNL; - 27th February 2012 at 19:23. Reason: Typo

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: PIC18F14K50 and i2cread/i2cwrite on PORT C

    Quote Originally Posted by RuudNL View Post
    TRISB=0 sets the outputs to a solid low level, but the I2C commands are still not working.
    Don't do that.
    I2C requires the pins to be in INPUT mode when not transfering data.
    The pins are never driven high, only low, which is why you need the pull-up resistors.

    Since it's a 14K50, you're probably running at 48Mhz.
    So you may want to add ...

    DEFINE I2C_SLOW 1

    Depending on if the device you're talking to is a 100Khz I2C part.
    If it's a 400Khz part, you won't need it.
    DT

  6. #6
    Join Date
    Feb 2012
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: PIC18F14K50 and i2cread/i2cwrite on PORT C

    I know...
    The only reason I tried TRISB=0 is because I wanted to check if I could use the pins as a digital output.
    In the meantime I found the problem. In fact, it had nothing to do with the i2cread/i2cwrite commands.
    The crystal I used apparently had a low activity. Sometimes the oscillator was working, but most of the time it was not!
    I changed the crystal and now it works! (Maybe changing the values of the capacitors would have worked, but I did not try that.)

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