Push-pull VS open-drain.
At the end of the previous article I promised to explain how a push-pull (PP) output differs from an open-drain (OD) output.
To understand this, let's look at how a push-pull output is built.

Essentially, it consists of two switches: one pulls the pin up to the supply, the other pulls it down to ground.
And now open-drain.

The picture shows that open-drain can be with or without an internal pull-up.
If you use the pull-up, it becomes completely unclear how it differs from push-pull.
Now let's think about what happens if we connect two PP outputs together and set different logic levels on them.
Because of the level conflict, one of the outputs will simply burn out, since the current caused by the potential difference is not limited by anything.
Now let's connect two OD pins in the same way.
You can see that the line potential is pulled to ground and nothing burns. Therefore, OD pins can be connected together without fear of burning anything. And if one pin can sink 20 mA, then by combining 5 pins you can sink 100mA through them.
This is the case where PP cannot replace OD.
Now imagine another situation: there is a data bus, for example I2C, whose logic one doesn't match our MCU's voltage and is either 1.8 or 5 volts. In both cases you can't connect the MCU to such a bus using a PP output, because PP can output neither 1.8 nor 5 volts. But it's very easy to do with OD and an external pull-up resistor.

That's all; in the next article I'll describe how to detect a stack overflow.
To understand this, let's look at how a push-pull output is built.

Essentially, it consists of two switches: one pulls the pin up to the supply, the other pulls it down to ground.
And now open-drain.

The picture shows that open-drain can be with or without an internal pull-up.
If you use the pull-up, it becomes completely unclear how it differs from push-pull.
Now let's think about what happens if we connect two PP outputs together and set different logic levels on them.
Because of the level conflict, one of the outputs will simply burn out, since the current caused by the potential difference is not limited by anything.
Now let's connect two OD pins in the same way.
You can see that the line potential is pulled to ground and nothing burns. Therefore, OD pins can be connected together without fear of burning anything. And if one pin can sink 20 mA, then by combining 5 pins you can sink 100mA through them.
This is the case where PP cannot replace OD.
Now imagine another situation: there is a data bus, for example I2C, whose logic one doesn't match our MCU's voltage and is either 1.8 or 5 volts. In both cases you can't connect the MCU to such a bus using a PP output, because PP can output neither 1.8 nor 5 volts. But it's very easy to do with OD and an external pull-up resistor.

That's all; in the next article I'll describe how to detect a stack overflow.


