3

Using a Pico [RP2040], I wish to interface to a data bus which is (already) pulled high.

(Based on the contents of the address bus) I want to put data on the data bus [ie. "memory mapped i/o"]

But I cannot find reference to HiZ on GPIO pins in the RP2040 datasheet!?

I am working in 'C', so I have set up my GPIO pins with:

gpio_init_masked(ADDR_MASK | DATA_MASK);
gpio_set_dir_in_masked(ADDR_MASK);
gpio_set_dir_out_masked(DATA_MASK);

...and I can "put a 0 on a data pin" with:

gpio_put(DATA_D0, (bool)0);

Two questions:

  • Do I need to initialise the DATA pins to HiZ, or is that the default state? ...If so, what function do I use with what parameters?
  • What function do I need to call with what parameters to put DATA_D0 back to HiZ (when the address bus changes)
8
  • 1
    you could permanently set the output LOW and then switch between OUTPUT and INPUT ... one would drive the data line LOW ... the other would allow the data line to float, the pullup resistor on the data line would pull it HIGH
    – jsotola
    Nov 5, 2022 at 18:06
  • I'm still intrigued to know if my idea is possible (as it has a certain pleasing continuity-of-logic to it) ...But if not: That's a rather devious and genius work-around! Thank You :)
    – BlueChip
    Nov 5, 2022 at 19:55
  • 1
    @nonchip Having been playing for a couple of months now, I've come to the conclusion that Output is always 1 or 0; and HiZ is actually "not output" (ie. input). And hence "my idea" was simply born of ignorance: ie. I was originally of the belief that Output had three states {1, 0, HiZ} - thus thinking that "use input as HiZ" was a "workaround" ...I have upvoted jsotola's comment. If (s)he repeats it as an "answer" I will "accept" it :) ...I would add it as a self-answer, but that feels disrespectful to jsotola
    – BlueChip
    Jan 17, 2023 at 18:23
  • 1
    @BlueChip oh yes, the "output (=pin)" has three states because "not connected to anything because it's not configured as an output (=function) right now" is one of the states you can get "out" of the physical piece of wire. i guess it's a "workaround" in the sense that the software has no "third value" for that boolean and you're telling it to be an input that's never read so the code might look unintuitive at first glance, but in the electrical sense that's not considered ugly/bad practice or anything, that's how almost all busses ever work and perfectly fine :)
    – nonchip
    Jan 18, 2023 at 6:57
  • 1
    @BlueChip but yeah, to summarize: "pin direction = output, put value = 0" -> pin becomes internally connected to GND, "pin direction = output, put value = 1" -> pin becomes internally connected to VCC, "pin direction = input" -> pin becomes internally disconnected from any power rails (= "high impedance") and just measured (that's the "input" bit we ignore). so if you set it to "always 0" and switch the direction, then use an external "mid impedance" (ballpark of 10-100K) to weakly pull it up to VCC, it defaults to 1 but can be overridden to 0 by any number of pins without shorting the circuit
    – nonchip
    Jan 18, 2023 at 7:06

1 Answer 1

1

AFAIK this is not possible (I am assuming Pico GPIO similar to Pi based on limited experience) as there is no command to Tri-state.

What other applications do is put in INPUT mode which is high impedance.

Just to be clear there is NO Tri-state.

When in INPUT the pins will be high impedance; just ignore the value.

It would actually make no sense to have a Tri-state; the GPIO buffers values in a dedicated register but there is no obligation to do anything with the value. This differs from a conventional CPU where INPUT actually puts something directly into a CPU register.

3
  • 1
    I think we have a 'jargon' confusion. I believe the three states of "tri-state" are OUTPUT={HIGH, LOW, Hi-Z (aka "high impedance")} ...If that is wrong, what are the three states of "tri-state"?
    – BlueChip
    Nov 5, 2022 at 19:52
  • That is correct. However it is not supported by the GPIO. Unlike a more conventional CPU the Pico is not designed to support a bus.
    – Milliways
    Nov 5, 2022 at 21:40
  • 1
    how could it be "not supported" when it's literally how the GPIO always works? of course switching the pin direction to input is HiZ. milliways is confusing a "input instruction" on whatever they think a "conventional cpu" is supposed to be (because MMIO happens a lot actually, and i haven't seen that many "input" instructions since the likes of the Z80) with the pin direction register you're talking to.
    – nonchip
    Dec 29, 2022 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.