2023-11-28 08:24 AM
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,
Solved! Go to Solution.
2023-11-28 10:19 AM
you have to isolate the cpu pin ALWAYS !
keep to the 35 y old standard:
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 );
2023-11-28 09:09 AM - edited 2023-11-29 12:20 AM
Hello,
Note that the maximum output current sunk by any I/O on STM32F373 is 25mA:
From the datasheet:
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.
2023-11-28 09:15 AM
> 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:
2023-11-28 10:02 AM - edited 2023-11-28 10:06 AM
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...
2023-11-28 10:19 AM
you have to isolate the cpu pin ALWAYS !
keep to the 35 y old standard:
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 );
2023-11-28 10:35 AM
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.
2023-11-28 11:25 AM
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:
2023-11-28 01:44 PM
Have I wired this up correctly to isolate the STM32F373's USART TX?
2023-11-29 12:17 AM
yes, perfect !