I have been trying to make work the GPIOs in the open drain output mode and I´m not able to use it. I have been using the other output modes as the push-pull, but making similar probes in the open drain mode it doesn´t work.
Configured them as ->cfgpio 0,4,0 (I have tried with another GPIOs too)
and then change the state with pio0=1 and pio0=0.
It doesn´t mind if the state is 1 or 0, the current never circulates.
The fisical connections to make the probes have been:
5V->Led ->Resistance ->GPIO
I understand that when pio0=1, the GPIO would make an internal connection with ground, but it doesn´t happen.
Could someone help me?
PD: Sorry for my English
You maybe have a slightly wrong understanding of "Open Drain" ...
The push-pull output actually uses two transistors. Each will be on to
drive the output to the appropriate level: the top transistor will be on
when the output has to be driven high and the bottom transistor will
turn on when the output has to go low.
The open-drain output lacks the top transistor. When the output has to go high you simply turn off the bottom transistor, but the line is now pulled high only by the pullup resistor.
Your micro allows you to select between the two types, which means that by setting some bits in some register you actually enable/ disable the top transistor and enable/disable the pullup (if internal, otherwise you just disable the top transistor and have to use an external pullup)
The advantage of the push-pull output is the higher speed, because the line is driven both ways. With the pullup the line can only rise as fast as the RC time constant allows. The R is the pullup, the C is the parasitic capacitance, including the pin capacitance and the board capacitance.
The push-pull can typically source more current. With the open-drain the current is limited by the R and R cannot be made very small, because the lower transistor has to sink that current when the output is low; that means higher power consumption.
However, the open-drain allows you to cshort several outputs together, with a common pullup. This is called an wired-OR connection. Now you can drive the output low with any of the IO pins. To drive it high all ouputs have to be high. This is advantageous in some situations, because it eliminates the external gates that would otherwise be required.
Your application may require connecting several outputs together on a single I/O line. In this case, you should use the Open Drain feature to avoid the situation when different outputs set different signal levels on the line. To avoid hardware damage all interconnected outputs should be in open drain mode.
In open drain mode, pin cannot output high level (logical 1) on the line. It can either output low level (logical 0) or be in high-impedance state (logically disconnected). In high-impedance, pin does not affect the signal level on the line. A pull-up resistor pulls the line to high voltage level when all outputs are in high-impedance.
Thanks for answering so quikly and for giving a very good explanation.
Maybe I am still thinking wrong, but I believe that the concept of the open drain output is the same that the one I had.
What I tried to explain is this simple circuit that I was trying. The GPIO is configured as open drain output, and what I expected to read in the measurement point was 5V when the internal transistor is not turned on (output in high impedance), and a voltege similar to 0V when the internal transistor is turned on.
Instead of that, I always have a measure of 5V, so I´m not able to turn on the output.
To make soure that is not a Code error or another kind of problem, tried the same schematic with the push-pull output configuration (with the expected results).
So, there is something that I´m not able to understand.
Thanks in advance.