[
RP2040 doesn't explicitly support open-drain (== open-collector) outputs. However, you can achieve exactly the same effect by setting an output to '0' and then switching the output enable on and off - when it's enabled, RP2040 will drive that '0' onto the wire, when disabled it will not drive the wire and the pull-up resistor will cause it to rise to '1'.
Again, there isn't a separate 'output enable' setting for the I/O pins, but there's a 'direction' setting which does the same thing - PINDIRS. When the corresponding bit in PINDIRS is set to '1' then the pin is an output and drives whatever is in its output register; when the PINDIRS bit is '0', the pin is an input and is not driven.
---------
Here is another angle : A pin configured as an input has a very high output impedance and thus will allow an open/collector/drain bus to go high. An open/collector bus does not need to be driven high: it is always high when idling: no device is pulling it low.
Note: the following is assuming that gpio pin is associated with an open/collector/drain bus or device.
RP2040 doesn't explicitly support open-drain (== open-collector) outputs. However, you can achieve exactly the same effect by setting an output to '0' and then switching the output enable on and off - when it's enabled, RP2040 will drive that '0' onto the wire, when disabled it will not drive the wire and the pull-up resistor will cause it to rise to '1'.
Again, there isn't a separate 'output enable' setting for the I/O pins, but there's a 'direction' setting which does the same thing - PINDIRS. When the corresponding bit in PINDIRS is set to '1' then the pin is an output and drives whatever is in its output register; when the PINDIRS bit is '0', the pin is an input and is not driven.
---------
Here is another angle : A pin configured as an input has a very high output impedance and thus will allow an open/collector/drain bus to go high. An open/collector bus does not need to be driven high: it is always high when idling: no device is pulling it low.
Note: the following is assuming that gpio pin is associated with an open/collector/drain bus or device.
Code:
; the following sequence is allowed on open/drain/collector busset pindir 0; this affectively release the bus because of the high output impedance of an input pin. ; affectively the bus is now high (normal idle state.); the following sequence is normal on open drain/collector busset pindir 1; pin is an output pin. set pins 0; pin now has low output impedance pulling the open/drain/collector bus low. set pindir 0; this will release the bus (letting it go high) because of the high output impedance of an input pin. ; the following sequence not allowed.set pindir 1 ; configure pin as an output pin.set pins 1; set the state high; never do this on a pin associated with an open drain/collector bus ; the bus does not need to be driven high; it is normally high at idle due to pull up resistor to vcc.; if you want to set the bus high without writing a 0 to it; simply configure pin as input e.g. <set pindir 0>Statistics: Posted by Henderson Hood — Mon Apr 14, 2025 9:07 pm