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.

EK-TM4C129EXL: GPIO PORT Configuring.

Part Number: EK-TM4C129EXL

I am working with EK-TM4C129EXL control card. I tried to configure the Port as Input/ Output.

I successfully configured it by using  GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

Then I tried to write the values to the pin using  GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0);

How to write the value to the port instead of writing to a particular pin ????

  • Naveen Kumar29 said:
    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0);

    It would 'surprise' - if your call to, 'GPIOPinWrite()' - as you've listed (above) - succeeds!

    Why's that?    Your adoption of - and compliance with - the 'TM4C Peripheral Driver Library (PDL) User Manual' reveals that, 'THREE Parameters' - not just TWO (as your code reveals) are required!    That (missing) middle parameter - is in fact - 'KEY' to your achieving your desired, 'FULL PORT WRITE' - rather than a write to an individual pin!

    Follows the key extract from the PDL manual.    (really - 'MUST Reading'  - for you/moi/others.)

    14.2.3.48  GPIOPinWrite
    Writes a value to the specified pin(s).
    Prototype:
    void
    GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)     //   bold reveals the parameter you 'missed'

    Parameters:
    ui32Port is the base address of the GPIO port.
    ui8Pins is the bit-packed representation of the pin(s).
    ui8Val is the value to write to the pin(s).
    Description:
    Writes the corresponding bit values to the output pin(s) specified by ui8Pins. Writing to a pin configured as an input pin has no effect.
    The pin(s) are specified using a bit-packed byte, where each bit that is set identifies the pin to be accessed, and where bit 0 of the byte represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on.

    In your case - to address a 'Full Port' - you may enter (255 or 0xFF) for (necessary) parameter two.    (you may also employ 'GPIO_PIN_N' - where N includes each entry (0 - 7) - and you don't mind  'Carpal Tunnel Syndrome and/or great waste of time/effort.')

    Only those pins 'appearing' w/in Parameter Two will accept your Write Command.     (i.e. if param. 2 is 0xFC, and param. 3 is 0xFF - then port bits 0 & 1 will not be written (set).)

  • Hello Naveen,

    To add to what cb1 stated, as you questioned how to write to a whole port, you can use GPIOPinWrite to write to multiple pins, just OR them together as you did for the GPIOPinTypeGPIOOutput.
  • I would (still) believe that the 'middle parameter' (which poster MISSED) IS REQUIRED!
  • Absolutely. Hence "to add to what cb1 stated". Just wanted to let him know it's valid to do:

    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

    In order to write to multiple pins. :)
  • This is the code I am working on,

    int bitShift=0;
    int pin = 0;

    pin = bitShift;
    pin |=(1<<3);                  // To OR the Pin value with port value

    /* Writing bitShiftvalue to  PORTE */

    GPIOPinWrite(GPIO_PORTE_BASE, 0x0F , pin);

    Is this Correct ???? When looped to shift each bit of the bitShift (i.e 8-bit value), would it work???

  • Hello Naveen,

    As long as you have strong understanding of how the bit shift affects the output (i.e. what you posted would turn on Pin 3 and none of the others) then the code you posted should work.

    That said, I would not hard code the 0x0F but rather use the TivaWare macros OR'd together. This makes the code more readable as then anyone looking at it can understand it is for specific pins on the ports.