Electrical – Understanding PIC32 digital output with open-drain

open-drainpic

I'm trying to understand how to operate digital pins configured as open-drain outputs on a pic32. As I've read on other forums, setting TRISx to 0 and ODCx to 1 configures the pin as open-drain output, and writing 1 to LATx will drive the output high-Z (w/pullup resistor) and writing 0 will drive it low.

Source: http://www.microchip.com/forums/FindPost/789946

If you have an actual open drain output, you can keep TRIS low and control the transistor with LAT. LAT=0 => transistor closed to ground and the output will be low, LAT=1 => transistor open and output will be floating or clamped high with a resistor (or pulled low by another signal).

What I'm caught up on is this part of the diagram for the pins:

Figure 12-1 snippet

From the PIC32 IO Port Reference Manual

What does ODCx do if TRISx is set 0? The output of the multiplexer controlled by ODCx will be low no matter what, as its either TRISx or (TRISx AND 'LATx), which will always be 0 when TRISx is 0.

Best Answer

p12-3 from I/O Ports under 12.2.4 Registers for Open-Drain Configuration (ODCx):

n. If the ODCx bit for an I/O pin is a ‘1’, the pin acts as an open-drain output.

and:

The ODCx register setting takes effect in all the I/O modes, allowing the output to behave as an open-drain even if a peripheral is controlling the pin. Although the user could achieve the same effect by manipulating the corresponding LATx and TRISx bits, this procedure will not allow the peripheral to operate in Open-Drain mode

To enable Open-Drain mode, you have to use ODCx.

p12-3 under 12.2:1 Registers for Configuring Tri-state Functions (TRISx)

If data direction bit is ‘0’, the corresponding I/O port pin is an output

and under 12.2.3 Registers for Configuring Latch Functions (LATx)

A write to a LATx register latches data to corresponding port I/O pins. Those I/O port pin(s) configured as outputs are updated.

So ODCx = 1, TRISx = 0. Then output a 0 to LATx and output is driven low. A 1 and output is open-drain with pull-up to a max of \$V_{IH}\$.

Which agrees with your thoughts, web. But it is always better to go to the data sheet.

Related Topic