Electronic – Do you have to set the TRIS register when using open collector outputs on Microchip microcontrollers

microchipmicrocontrolleropen-collectortri-state

I'm using a dsPIC33FJ series microcontroller from Microchip. It has dedicated open-collector outputs/registers.

I've read the documentation and it is extremely brief. Does setting the ODCx register have precedence over the TRISx registers? Or do I need to configure the TRISx registers to some setting as well when I am in open-collector mode? I don't have the hardware to test this right now.

Thanks,

Best Answer

Think about it. The open drain feature would not work as intended if you had to keep the TRIS bit set. That would keep the output driver high impedence. What open drain does instead is switch to high impedance when the output would otherwise be high, but still actively pull low when the output is supposed to be low.

So if you want to use a pin in open drain mode, set the ODC bit to 1, the TRIS bit to 0, and then set the LAT bit according to the data you want. When the LAT bit is 0, the pin will actively pull low. When the LAT bit is 1, the pin will be in high impedance mode.