Author Topic: How to define a microcontroller pin as open collector or open drain??  (Read 2978 times)

0 Members and 1 Guest are viewing this topic.

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: gl


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??



 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6420
  • Country: de
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #1 on: January 06, 2019, 07:50:37 pm »
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.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14117
  • Country: gb
    • Mike's Electric Stuff
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #2 on: January 06, 2019, 08:02:55 pm »
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.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: gl
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #3 on: January 06, 2019, 08:04:27 pm »
 I2C communication require two pull up resistor for SDA and SCL.
 Are SDA and SCL  open-drain output pins???
« Last Edit: January 06, 2019, 08:24:52 pm by khatus »
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 305
  • Country: gb
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #4 on: January 06, 2019, 08:11:13 pm »
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
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #5 on: January 06, 2019, 08:15:00 pm »
I2C communication require two pull up resistor for SDA and SCL.
.Is SDA and SCL are open-drain output pins???

Yes, when pins are configured/associated with I2C peripheral. Usually same pins have push-pull operation in GPIO mode.
 

Offline khatusTopic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: gl
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #6 on: January 06, 2019, 08:48:10 pm »
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??
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9963
  • Country: us
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #7 on: January 06, 2019, 08:52:25 pm »
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).
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 4000
  • Country: us
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10031
  • Country: gb
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #9 on: January 06, 2019, 09:49:06 pm »
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).
Its 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.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #10 on: January 06, 2019, 10:02:01 pm »
In addition to what's said, some uC have open drain GPIO mode for other than I2C pins. One example is stm32 series

Also it is worth to mention that internet search is much more powerful tool than forum post. Results come lot faster ;)
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 4000
  • Country: us
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #11 on: January 06, 2019, 10:30:17 pm »
I would add that the newer 8-bit PIC's (e.g., 16F1783) allow the user to define open drain for almost any pin.
 

Offline Wimberleytech

  • Super Contributor
  • ***
  • Posts: 1134
  • Country: us
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #12 on: January 06, 2019, 11:03:41 pm »
I would add that the newer 8-bit PIC's (e.g., 16F1783) allow the user to define open drain for almost any pin.

Many (if not all) of the Silabs MCUs do this as well.  The early 8-bit ones do for sure.
 
The following users thanked this post: ogden

Offline emece67

  • Frequent Contributor
  • **
  • !
  • Posts: 614
  • Country: 00
Re: How to define a microcontroller pin as open collector or open drain??
« Reply #13 on: January 06, 2019, 11:05:14 pm »
.
« Last Edit: August 19, 2022, 02:10:10 pm by emece67 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf