How to define a microcontroller pin as open collector or open drain??

Thread Starter

khatus

Joined Jul 2, 2018
89


https://www.microcontrollertips.com/what-is-an-open-drain-faq/

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??Does any pin of a micro controller can be used in open drain configuration??

2. If i define a GPIO pin as an input pin, Can I use this pin in open drain configuration?
3. Does it mandatory to define a pin as output for using it in open drain configuration??
 

AlbertHall

Joined Jun 4, 2014
10,542
You will need to check the datasheet for the particular μC you are going to use.
On most small microchip PICs The pins can be inputs or outputs only. You can simulate open drain by making the pin an input when it should float high and then set it to output low when the pin should be low. So this processor cannot officially do open drain, but using the method above the external circuitry won't know, though the software needs to be written for this circumstance.
 

jpanhalt

Joined Jan 18, 2008
10,480
On many of the newer PIC's the individual pins can be set to "open drain." Here's a snippet from the 16F1783:

upload_2019-1-6_15-17-11.png

@khatus
Your question cannot be answered without knowing which device you are using and which pin(s).
 

Thread Starter

khatus

Joined Jul 2, 2018
89
I am using PIC 18f4550. If I2C communication require two pull up resistor for SDA and SCL. Are SDA and SCL open-drain output pins???
 

AlbertHall

Joined Jun 4, 2014
10,542
I am using PIC 18f4550. If I2C communication require two pull up resistor for SDA and SCL. Are SDA and SCL open-drain output pins???
From the datasheet:
Selection of any I 2 C mode with the SSPEN bit set
forces the SCL and SDA pins to be open-drain,
provided these pins are programmed as inputs by
setting the appropriate TRISC or TRISD bits. To ensure
proper operation of the module, pull-up resistors must
be provided externally to the SCL and SDA pins.
 

Thread Starter

khatus

Joined Jul 2, 2018
89
So if i define SCL and SDA pins as input pin by setting the appropriate TRISC or TRISD bits.The pins act as current sink??
But if i define them as output will they act as current sink or current source??
 

AlbertHall

Joined Jun 4, 2014
10,542
You program them as inputs and the I2C module handles them as open drain automatically when the program reads or writes to the I2C.
 

Thread Starter

khatus

Joined Jul 2, 2018
89
So it does not matter whether a pin is defined as input or output(by setting the appropriate bits).
Structurally If the pin is an open drain pin, then it must require an external pull up resistor to operate??
 

AlbertHall

Joined Jun 4, 2014
10,542
So it does not matter whether a pin is defined as input or output(by setting the appropriate bits).
Structurally If the pin is an open drain pin, then it must require an external pull up resistor to operate??
In the case of the I2C pins on the PIC18f4550 while being used for I2C communication you set the I2C pins as inputs and the I2C module will correctly handle the signals on those pins as open drain.

When a pin is being used as open drain then it will need a pull-up of some sort to function correctly. That may be an external resistor or the pin may have the capability of an internal pull-up which could be turned on.
 
Top