cancel
Showing results for 
Search instead for 
Did you mean: 

Getting more current from GPIO

LMorr.3
Senior II

I'm using an STM32F373's UART to output MIDI data.  Basiclly the TX USART pin needs to light an LED in the MIDI cable's opto-coupler.  I currently have the TX pin connected directly to the MIDI DIN connector pin through a 200ohm resistor.  

I know this is ok to power an LED locally on the PCB, but is this ok if the signal is powering an LED at the end of an external MIDI cable which potentially could be shorted or have power connected into it by mistake?  Should I isolate it the uC's TX pin?  ( was thinking using an 4N35 optoisolator like I did for the MIDI input/USART RX, but wanted to see if there was a more optimal design option.

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Principal III

you have to isolate the cpu pin ALWAYS !

keep to the 35 y old standard:

 

AScha3_0-1701194934625.png

https://www.midi.org/specifications-old/item/midi-din-electrical-specification

https://learn.sparkfun.com/tutorials/midi-tutorial/hardware--electronic-implementation

 

what i would do:  invert the cpu out signal, put an nice mosfet as output ,  ie IRLML6344 + 220 or 10 ohms (depends: you drive 5V or 3v3 pos.supply );

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

8 REPLIES 8
SofLit
ST Employee

Hello,

Note that the maximum output current sunk by any I/O on STM32F373 is 25mA:

From the datasheet:

SofLit_0-1701191192938.png

So if you have a doubt regarding the usage of the pin and there is a risk to short-circuit it or exceed the current mentioned above, I think it's preferable to isolate it with an optocoupler like you proposed or simply an external MOS transistor.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
TDK
Guru

> is this ok if the signal is powering an LED at the end of an external MIDI cable which potentially could be shorted or have power connected into it by mistake?

The STM32 GPIO pins generally do well if they are overdriven or shorted, provided the voltage is within the range of GND-VDD. The GPIO pins limit their output current in such an instance.

Not sure there's an optimal solution here. It depends on your goals and what you're trying to protect against in particular. Some other cheap/easy options:

  • Put the current limiting resistor on the STM32 side of the cable. Then any shorting which happens after that will be limited to about 16mA, within the limits of most pins.
  • Separate the LED from the STM32 by driving it with a transistor. Then the STM32 only supplies the base current, which is negligible, and downstream matters less, although you'll need to ensure the transistor doesn't burn up by limiting current.
If you feel a post has answered your question, please click "Accept as Solution".

Ok thanks.  I'll use a MMBT3904 transistor.  

Now that I use a transistor for TX, the output is inverted.  Is it possible to set USART's TX to invert it's output and not invert RX, or should I use a component to invert TX?  I guess I could use a PNP instead of NPN...

AScha.3
Principal III

you have to isolate the cpu pin ALWAYS !

keep to the 35 y old standard:

 

AScha3_0-1701194934625.png

https://www.midi.org/specifications-old/item/midi-din-electrical-specification

https://learn.sparkfun.com/tutorials/midi-tutorial/hardware--electronic-implementation

 

what i would do:  invert the cpu out signal, put an nice mosfet as output ,  ie IRLML6344 + 220 or 10 ohms (depends: you drive 5V or 3v3 pos.supply );

 

If you feel a post has answered your question, please click "Accept as Solution".

Ok thanks.  I had read the spec however was concerned about the potential for shorting of cable with only 10ohm and 33ohm resistors in place. ( i'm using 3.3V source ).  Using the mosfet as you suggest would allow me to stick to the spec and also isolate the uC, thanks.

you can use any other mosfet, which can drive some current (1A or so) ;

maybe even the old 2N7002 is ok.

and dont forget to invert the uart output, on F373 can use:

AScha3_1-1701198015352.png

 

AScha3_0-1701197969492.png

 

If you feel a post has answered your question, please click "Accept as Solution".

Have I wired this up correctly to isolate the STM32F373's USART TX?

isolated_USART_TX.png

yes, perfect !

If you feel a post has answered your question, please click "Accept as Solution".