How to define a microcontroller pin as open collector or open drain?? - Page 1
Forum section: electronics / beginners

author: khatus
author_rank: Regular Contributor
timestamp: January 06, 2019, 07:45:03 pm
content: 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??

author: Benta
author_rank: Super Contributor
timestamp: January 06, 2019, 07:50:37 pm
content: It is extremely rare that microcontrollers have open-drain output pins, they're almost always complementary.If you need open-drain functionality, you'll extra hardware, eg, a MOSFET transistor.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: January 06, 2019, 08:02:55 pm
content: Some MCUs have explicit OD modes, but any bidirectional pin can be used as open drain by setting it as low output for on, and input as off.However note you can't externally pull it to higher than Vcc due to input protection diodes.

author: khatus
author_rank: Regular Contributor
timestamp: January 06, 2019, 08:04:27 pm
content: I2C communication require two pull up resistor for SDA and SCL.Are SDA and SCL open-drain output pins???

author: jimmc
author_rank: Frequent Contributor
timestamp: January 06, 2019, 08:11:13 pm
content: mikeselectricstuff has just beaten me to to it, but as he says you can emulate an open drain output by switching between output and input as required.Below are my comments from an Arduino based GPIB program. Here I wanted an 'open drain' with a weak pull up.// Asserted (Low state) digitalWrite(xx, LOW); pinMode(xx, OUTPUT), This way round to ensure output never 'glitches' to +5v// Unasserted (High state) pinMode(xxx, INPUT_PULLUP), High by internal pullup only (20-50 kOhm)Again as Mike said, beware the protection diodes to Vdd.Jim

author: ogden
author_rank: Super Contributor
timestamp: January 06, 2019, 08:15:00 pm
content: Quote from: khatus on January 06, 2019, 08:04:27 pmYes, when pins are configured/associated with I2C peripheral. Usually same pins have push-pull operation in GPIO mode.

author: khatus
author_rank: Regular Contributor
timestamp: January 06, 2019, 08:48:10 pm
content: 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??

author: rstofer
author_rank: Super Contributor
timestamp: January 06, 2019, 08:52:25 pm
content: Yes, you need some kind of pullup.The trick in many uCs as discussed above is to set the pin as input/pullup or set it as output/logic low. Basically, you spend more time manipulating the direction port than the data port. You set the output low at startup and then just toggle between input (open collector) an output (pulled down).

author: jpanhalt
author_rank: Super Contributor
timestamp: January 06, 2019, 09:36:45 pm
content: I believe the OP's question has been answered here:https://forum.allaboutcircuits.com/threads/how-to-define-a-microcontroller-pin-as-open-collector-or-open-drain.155631/#post-1342101

author: coppice
author_rank: Super Contributor
timestamp: January 06, 2019, 09:49:06 pm
content: Quote from: rstofer on January 06, 2019, 08:52:25 pmIts not a trick. The reason they don't put explicit open drain features in most MCUs is because the technique you describe is exactly what you need for an open drain multi-function pin. A true open drain would not have input protection circuitry clamping it, but then the pin would need to be a dedicated output pin, which is not a popular choice for MCU pins. Most customers are looking for the maximum possible functionality on every pin.

author: ogden
author_rank: Super Contributor
timestamp: January 06, 2019, 10:02:01 pm
content: In addition to what's said, some uC have open drain GPIO mode for other than I2C pins. One example isstm32 seriesAlso it is worth to mention that internet search is much more powerful tool than forum post. Results come lot faster

author: jpanhalt
author_rank: Super Contributor
timestamp: January 06, 2019, 10:30:17 pm
content: I would add that the newer 8-bit PIC's (e.g., 16F1783) allow the user to define open drain for almost any pin.

author: Wimberleytech
author_rank: Super Contributor
timestamp: January 06, 2019, 11:03:41 pm
content: Quote from: jpanhalt on January 06, 2019, 10:30:17 pmMany (if not all) of the Silabs MCUs do this as well. The early 8-bit ones do for sure.

author: emece67
author_rank: Frequent Contributor
timestamp: January 06, 2019, 11:05:14 pm
content: .