0
\$\begingroup\$

I configured a pin on my micro-controller(STM32F4-discovery) as an open drain and I wanted to connect it to a 5V pull-up network and drive an LED. The output of my pin is 3V so hence I wanted to pull up the pin to another voltage if I have another device that requires 5V. I am using an LED as an example to test the proof of concept, but I am confused that why it wouldn't work:

enter image description here

I have also been reading about Logic Level Converter recently where it can "convert" your 3V to 5V. Should I be using that instead?

\$\endgroup\$
  • 1
    \$\begingroup\$ Open-drain outputs are usually used for low-side switching. \$\endgroup\$ – Ignacio Vazquez-Abrams May 19 '18 at 7:31
  • \$\begingroup\$ The answer flagged by berendi shows you what will work. Adding a transistor greatly increases the flexibility available - LED current can be higher and load voltage is independent of uC capability. Using the pin as shown will work for LEDs with Vf lower than uC_Vdd. If the LED has a Vf of say 3V3 then the pin will be pulled to 3V3 when the pin is turned off - this will probably cause system malfunction if Vdd is 3V. Also, I_LED_max is the current that the uC pin can pull down to below the LEDs on voltage - say < 1.5V for a white LED and well under 1V for a red or IR LED. \$\endgroup\$ – Russell McMahon May 19 '18 at 21:33
  • \$\begingroup\$ As shown ILed is about (5V-Vled)/10k = about 0.2 mA dor a white LED and 0.3 mA for a red LED - You'll get light but it won't be bright. SO this arrangement CAN work for some values of "can" but adding a transistor gives MUCH better control and flexibility. \$\endgroup\$ – Russell McMahon May 19 '18 at 21:34
1
\$\begingroup\$

The question flagged by berendi shows you what will work, but does not fully cover some relevant aspects.

As shown the simple circuit (pin connected to LED to ground and resistor to V+ > Vdd) is potentially liable to cause incorrect system operation and in some cases to damage the uC (microcontroller).
Adding a transistor to drive the LED, as shown in that Q&A set, greatly increases the flexibility available - LED current can be higher and load voltage is independent of uC capability.

Using the pin as shown will work for LEDs with Vf lower than uC_Vdd. However:

  • If the LED has a Vf of say 3V3 then the pin will be pulled to 3V3 when the pin is turned off - this will quite possibly cause system malfunction if Vdd is 3V.

  • I_LED_max permissible is the current that the uC pin can pull down to below the LEDs on voltage - say < 1.5V for a white LED and well under 1V for a red or IR LED. This may be quite low, depending on the pin drive capability.

    As shown ILed is about (5V-Vled)/10k = about 0.2 mA for a Vf~=3V white LED and 0.3 mA for Vf ~= 2V a red LED. At those current levels, with typical LEDs you'll get light but it won't be bright.

SO this arrangement CAN work for some values of "can" but adding a transistor gives MUCH better control and flexibility.


The diagram below is from StevenH's answer to the 2012 question.

enter image description here

The LED supply voltage is shown as 3V3 but can be higher than Vdd subject to design of R2 and R3 values so that Vpin is never > Vdd when the pin is off/open-circuit and that Q2 received enough dreive when the pin is low.

As shown a bipolar transistor is used but a P channel FET would make design slightly easier.


The circuit below (from the 2012 question) would work as is with a standard (push-pull / high low) pin drive, or with an open drain pin if R32 was replaced with a wire and a suitable pullup resistor was added from transistor base to uC Vdd.
This circuit reverses the polarity of pin level and LED state. eg
Original - pin low = LED on.
With transistor - pin high = LED on.

enter image description here

\$\endgroup\$
0
\$\begingroup\$

This is what I do with an STM32F:

schematic

simulate this circuit – Schematic created using CircuitLab

But different LED and resistor value.

Make sure you keep the current of the LED to below the spec for open drain ports and don't use too many pins in this manner.

enter image description here

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.