When connecting GPIO output pins (RPi, uC, ...) to an opto-isolator, the classical way I know is the following (at least I understand that it can roughly be depicted like that):
This will, obviously, lead to the GPIO pins driving the opto-isolator's internal LED (in this case ~18mA). Depending on the amount of used pins, the total current allowed by the uC may be exceeded.
What if I was connecting the GPIO pin in the following manner:
For the sake of the question let's assume that both +3.3V are exactly +3.3V. The idea is to use inverse logic: if the GPIO is HIGH, both ends of the internal LED are on 3.3V, therefore no current is flowing and the opto-isolator is off. With GPIO LOW it connects to GND and therefore current is flowing through the opto-isolator, opening the 24V side as well. The advantage would be that the external power supply is driving the opto-isolator while the uC only has to sink the current.
Will this work? Is it even possible to have current flowing into an output pin while this is set to LOW? Or are there any internal resistors preventing this (specifically with an STM32F207 on a Nucleo-144 board 1)?
Also: will it even make a difference in terms of maximum allowed current? Is current flowing in taken into account just as current flowing out?