PDA

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



jellis00
- 6th August 2011, 00:25
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!

mister_e
- 6th August 2011, 00:42
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.

aratti
- 6th August 2011, 02:16
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.

jellis00
- 6th August 2011, 23:15
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?????

aratti
- 8th August 2011, 20:35
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.

jellis00
- 8th August 2011, 21:07
Thanks, Al. That definitely answers my question.

HenrikOlsson
- 8th August 2011, 21:50
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.