1
\$\begingroup\$

I am trying to drive this RGB using the GPIO of STM32F072. The GPIO can source around 25mA and the LED consumes around 20mA.
Would there be any issues?

\$\endgroup\$
2
\$\begingroup\$

Don't source more than 80mA. Absolute maximum. And you have to spread this 80mA over all GPIO banks.

The GPIOs (general purpose input/outputs) can sink or source up to +/-8 mA, and sink or source up to +/- 20 mA (with a relaxed VOL/VOH).

At 20mA, you'll be looking at VDDIOx –1.3V, so for 3.3V the output voltage can be as low as 2 Volt. (or as high as 1.3V sinking)

Looking at the forward voltages of your LED:

USD :1.6-2.4 V
NG :2.7-3.9 V
NB :2.7-3.9 V

This means you can only reliably drive the red led.

Don't drive the LED direclty from the chip. Use a LED driver or get an WS2812 or similar serial LED.

\$\endgroup\$
2
\$\begingroup\$

There will be issues.

In this case, it is a common anode LED so you would be sinking 60mA of current, which is a bit more relaxed than sourcing 60mA out of the MCU. Absolute max sinking limit for GPIO pins is 80mA so only 20mA is left for other IO pins to sink.

First misconception is that MCU can provide 25mA of current, but that is only the absolute maximum rating which is out of the range for normal use.

As specified in the electrical parameters section in the datasheet, IO pin sink/source current must not exceed 20mA during normal use.

The MCU itself can take up to about 28mA of supply current, depending on supply voltage, speed, and enabled peripherals. There are also max limits of 100mA per MCU ground pin and 120mA total for all MCU ground pins, and since it is hard to know how the currents are distributed inside the MCU so perhaps 100mA total limit is good worst case scenario. This actually leaves only 12mA for other GPIOs to sink, which may or may not be enough depending on what other devices you have connected.

As mentioned in another answer, the problem can be that LED forward voltage is so high that you can't use 3.3V supply to get 20mA flowing, and the LED may need to be connected to higher supply, so 5V tolerant IO pins on the MCU are needed to drive that.

So it would just be better to drive the LEDs with a transistor or a dedicated driver chip.

Note that the LEDs have different brightnesses, so if you want equal brightnesses for the LEDs, you would not drive all of them with maximum 20mA current, the green would be many times brighter. Also if you want a neutral white color the brightnesses need to be set according to how sensitive to human vision is to each LED wavelength, so in reality only one of the LEDs can be set to 20mA and other LEDs need to be scaled to less current accordingly.

\$\endgroup\$
1
\$\begingroup\$

No - just dont use pin PC13, PC14 and PC15 they cant drive more than 3mA

\$\endgroup\$
  • \$\begingroup\$ Where did you find this 3 mA? \$\endgroup\$ – Huisman Oct 17 at 6:56
  • 2
    \$\begingroup\$ @Huisman page 43 of datasheet: PC13, PC14 and PC15 are supplied through the power switch. Since the switch only sinks a limited amount of current (3 mA), the use of GPIOs PC13 to PC15 in output mode is limited: - The speed should not exceed 2 MHz with a maximum load of 30 pF. - These GPIOs must not be used as current sources (e.g. to drive an LED). \$\endgroup\$ – Jeroen3 Oct 17 at 7:09
  • \$\begingroup\$ Note that STM32 restriction applies only to the MCU sourcing current, not sinking. It is a common anode LED, so MCU would be sinking current anyway, not sourcing. \$\endgroup\$ – Justme Oct 18 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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