This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Tiva-C TM4C123x GPIO

Is it possible for on the fly changing of the GPIOs from INPUT to OUTPUT and vice versa? I've got 16 pins that will be acting like a data bus that need to be able to change depending on if its a read or a white. I know you can configure the pins to be open drain, but as far as I can tell from the documentation it seems like it will read back the last value written. I would think that I can just change the GPIO pins from an input to an output but there are some notes that make me think that once you call the GPIO_init() you can't make any other changes.

  • Hello Tom,

    There is no such restriction on changing IO direction. However there are some considerations to be aware
     of

    1. The 16-pins cannot be changed together from input to output and vice-versa. At any given time only 8-bits can be done, so there would be a delay of 2 clocks at least between one set of 8 pins and another

    2. When moving from input to output, it must made be sure that both sides are not driving opposite polarities. Over time it may lead to IO degradation

    3. When moving from output to input, the correct polarities are maintained, Use of Pull Up/Down is suggested.

    Regards

    Amit

  • Amit's identified your dual port requirement - I believe you'll need one more.  Most devices I've seen - which accept bi-directional data (in/out) - have distinct, strobe requirements.  (i.e. Write strobe, Read Enable, possibly a Chip Select, and sometimes 1 or more address/other control lines)  Thus - a 3rd port beckons/dawns.

    In the old days there existed 8255 (if memory serves) which provided 3 ports - either in or out - (and "on the fly" changeable) yet demands only 1 8 bit data port and 4 or so strobes/control signals.  Thus you're back to 2 MCU ports - but you've only a single port (rather than 2) which must switch from in to out.  (or vice-versa)

    Today such task may be achieved via FPGA/CPLDs - but that forces new & added demands.

    And - if absolute data rate is not mandatory - you may employ SPI into cascaded, 8 bit shift registers - yielding a (potentially unlimited size) combination of inputs and outputs.  This relaxes the demand upon the MCU to manage  multiple ports - and completely eliminates any/all input/output - "on the fly" reconfigs.  (i.e. SPI input always - and only - receives data from cascaded PISO (parallel in serial out) while SPI output drives cascaded SIPO (serial in parallel out).  Thus no bi-di data switching required!

    And - did we mention that SPI requires only single port management - not tri port - and eliminates demanding input/output switch-over management - required by parallel?  (i.e. you must positively prevent output to output signal contention!)

    Note too that the "world" has clearly adopted, "high speed serial bus" as the, "new way."  Had you considered the wiring/interconnect complexity of a 16 bit data bus - plus requisite strobes/control signals?  Four wires (perhaps 2, 3 added strobes = 1 Port!) is your "total" wiring/interconnect work-load via SPI.  Suspect SPI deserves rise in your consideration...

    Sometimes, "stunted focus" (i.e. MCU only) solutions may not prove best/brightest...  (and indeed - such MCU focus was introduced by poster - unchallenged by vendor - and perhaps (properly) illuminated/squawked at, here)

    Not enough (posted) data to recommend further - but your selection criteria (and understanding) may now be bit wider...