How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    I have to use Channel 11 (RB4) in my 18F4550 application as an analog A/D input. This then requires me to set ADCON1 = %00000011 which also makes all ANx channels analog except Channel 12. This therefore makes the two pins that are normally SCL/SDA also analog as Channels 10/12 respectively even though I don't want to use them as analog. I need to use the SCL/SDA interface to digitally control and read a DS1337 clock in my application. Is there any way to keep SCL/SDA available as digital I/O while using Channel 11 as an analog A/D input? It appears from the data sheet table for ADCON1 that this is not possible. I can't believe MICROCHIP would design these chips so that you can't simultaneously use the A/D channels associated with the RB pins while using the SCL/SDA for I2C bus!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    They're not going to work at the same time so... change ADCONx use the ADC, set ADCON to use SCl/SDA and so forth. no problem with that.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    Since you will use the18F4550 as master, there is no need to use SCL/SDA pins, you can use any available couple of pins for the I2C communication with DS1337 (the slave)

    It will be mandatory to use SLC/SDA only if 18F will act as a slave on the I2C bus.

    Cheers

    Al.
    Last edited by aratti; - 6th August 2011 at 02:18.
    All progress began with an idea

  4. #4
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    Thanks Steve and Al for your ideas. I guess I must have been having a senior moment....I should have thought of the idea of multiplexing the ADCON settings since I am not using the I2C bus at the same time as I am measuring temperature on AN11. I implemented this and it works fine. Thanks for suggestion!

    Al, your suggestion to use any available two pins for the I2C communication makes me ask whether it is possible by just substituting any pins for the normal RB0 and RB1 pins in the I2CWRITE statements as follows:
    ' Clear RTC STATUS and set CONTROL registers for next RTC interrupt
    I2CWRITE PortB.5, PortB.6, RTCdevice, StatusReg,[$00]
    PAUSE 10
    I2CWRITE PortB.5, PortB.6, RTCdevice, ContReg,[%00000101]
    Would like to understand the syntax that would have to be used in I2CWRITE statement just to subtitute any two available pins for the SDA, SCL pins?????

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    Page 85 of PBP shows a diagram connecting 24LC01 to a pic 16F84. This should answer your question. As I have already mentioned in my previuos post, the use of SLC/SDA pins is mandatory only if your intention is to use the pic as a slave device. In such a case you will need to use all the registers associate with SLC/SDA. Using the pic as a master you don't need any of those register but the two instructions I2CREAD and I2CWRITE will take care of all the timing necessary for the two ways communication. Remember to use pullup resistors (2.2k to 4.7k)

    Cheers

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    Thanks, Al. That definitely answers my question.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: How to use RB associated A/D channels simultaneously with SCL/SDA for I2C bus?

    As I have already mentioned in my previuos post, the use of SLC/SDA pins is mandatory only if your intention is to use the pic as a slave device.
    Actually, I'd say it's mandatory if you intend to use the MSSP module (which can handle master- AND slavemode). But then, as Al says, you don't use I2CRead/Write as those are bit-banged and doesn't utilise the hardware and can therfor use "any" available pins - just as Al says.

    /Henrik.

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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