Tony Nixon wrote: > I though if an anlog pin was set as an output you could use it as > an output pin capable of driving whatever. That's true, Tony. > I could not get the I2C eeproms to work. > .... > I had RA3 controlling the SCL line, and analog enabled with RA0, > RA1 and RA3 set as analog. (ADCON1 set as 04h) RA3 was set as an > output, not as an input. > > This did not work. I turned off the A2D and it did work. > > I've now swapped the SCL pin to RC0 and all works OK with A2D enabled. > > Anyone know why? If a pin is configured as an Analog Input, its digital state can NEVER be read... Not by a "MOVF PORTA,W", not by a "BTFSS PORTA,3", and not by the implied reads of read-modify-write instructions like "XORWF PORTA". Whenever you try to read the pin's digital state, you'll always see a "0". What you may not know is that "BSF" and "BCF" are read-modify-write instructions, too; they work by reading the entire port, setting or clearing one bit, then writing the entire port back. Check this out: ; ADCON1 = 0x04, TRISA = xxxx0000 MOVLW 00001000B ;RA3 = 1. MOVWF PORTA ; BSF PORTA,2 ;Read PORTA, set bit 2, then write ;it back out. In the process, RA3 ;is inadvertently cleared. After that last line executes, RA2 will be set but RA3 will be CLEAR: The BSF instruction reads a "0" in bit 3, then writes that "0" back out after setting bit 2. The only safe way to write to RA3 is via instructions which don't read the port first... In actual practice, this usually means that you do all your read-modify-write operations on a "shadow" register in RAM, then just copy that register to PORTA when needed. -Andy === Andrew Warren --- aiw@cypress.com === Cypress Semiconductor Corporation === Interface Products Division, S.D. === === The opinions expressed above do === not necessarily represent those of === Cypress Semiconductor Corporation. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.