Electrical – How to define a microcontroller pin as open collector or open drain

i2cmicrocontrollermosfettransistors

enter image description here

Source

I have understood the fundamental theory of open collector and open drain configuration. But the problem is how to define/make a micro controller's pin as open drain? Can any pin of a micro controller can be used in open drain configuration??

  1. If I define a GPIO pin as an input pin, can I use this pin in open drain configuration?
  2. Is it mandatory to define a pin as output for using it in open drain configuration?

Best Answer

Whether an output is an open drain or open collector or something else is a question of hardware design.

An open collector output has to be built so that the output pin is connected to the collector of a transistor of the chip - and the collector is connected to nothing else.

If a chip isn't designed with an open collector output, the no amount of configuration will get you one.

That said, many microcontrollers are designed to have switchable GPIO pins. You can configure a pin to be input or output, and you can configure what type of output.

What combinations are possible depends on what the hardware manufacturer decided to build into the hardware.