On Thu, 1 Jan 1998 01:31:33 +0300 Dmitry Kiryashov writes: [I wrote] >> While the PIC is outputting high, >> the OC In/Out pin can be read to determine the level on the bus. I should clarify that in order to 'output high' to an open collector bus, the PIC pin should be set to input mode (unless it is the RA4 pin, in which case it is OK to leave it output and set it high, since it has no pull-up output transistor). The pull-up resistor on the bus then raises the bus voltage to 'high' level. So OC In/Out is either set as output and low (to output low) or to input (to output high or input). It should not be set to output and high as this would supply extra current to devices on the bus (through R1 in this case, or directly if the sensing circuit isn't used). >There are also another idea how to make open-drain with only one PIC >pin. >Let us look at diagram below: > >1. PIC pin is set as input >1a. Bus=HIGH => PIC pin=HIGH too (transistor in active mode) >1b. Bus=LOW => PIC pin=LOW too (transistor in saturation) > >2. PIC pin is set as output >2a. PIC pin=HIGH => Bus=free (transistor is off) >2b. PIC pin=LOW => Bus=LOW (transistor in saturation) > > Bus > | > | > |/c > +5v--R1--| NPN > |\e > | > R2 > | > PIC in/out pin > This scheme does not solve the original poster's problem(?) of being able to tell if some other device is trying to pull the bus low at the same time the PIC is. Since the PIC pin must be forced low to turn the transistor on, it is not possible to read any meaningful value back in this condition. It is a useful circuit, however, to isolate the PIC from the bus while the PIC power is removed. The +5V to R1 would come from the same source that powers the PIC. When this voltage goes to 0, the transistor stays off all the time and no current flows from the bus to the PIC. Usually a FET is used as it has less voltage drop when the PIC is trying to pull the bus low. > >R1 & R2 resistance resulting from Bus specification and >type of transistor and may vary from 5KOhm to 500KOhm . I think in most cases R2=0 would be best. The value of R1 is not critical at all, it needs to be enough to bias the transistor on fully while the PIC is draining its maximum current from the bus. Using a FET, R1 could be omitted as well.