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.

TM4C123 use PA1 as GPIO

Hello!

I'm using a microcontroller TM4C123GH6PMI on the own design board. I try to configure PA1 as GPIO OUT using next steps:

HWREG(GPIO_PORTA_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;

HWREG(GPIO_PORTA_BASE + GPIO_O_CR)  |= GPIO_PIN_1;

GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1);

But it does not work. I can not set HIGH or LOW voltage on this pin.

Regards,

Petr

  • Hello Petr

    PA1 is not a locked pin so the unlocking sequence is not required. Now coming to issue of PA1 not working in GPIO Output Mode, what is the API you are using to make the pin 1 or 0? Also to note at this point is that the signal level will be logical 0 if there is no driver on the pin other than TM4C device and it is not clear what you have connected to PA1?

    If it is GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, 0x1); then please replace it with GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, GPIO_PIN_1);

    Regards
    Amit
  • Hi Amit,

    To provide this poster - and others - another version of your good answer they should realize that the API function:

    "GPIOPinWrite()" demands 3 parameters:

    • The targeted 8 bit wide port
    • a port "mask" which may include one, several, even all of that port's pins
    • a final value - "weighted" by the particular "bit position."   For instance bit_0 is weighted 1, bit_1 = 2, bit_4 = 8, bit_7 = 128.   Thus - if you entered 255 w/in the 2nd parameter (the mask) and then 128 w/in parameter 3 - you'd turn on port bit 7.   By removing 128 from parameter 3 - you'd clear that bit_7.   You are able to combine bits - turn ON & OFF multiple bits (from the same port, only) in one go.  For instance - if param. 2 (mask) contains 0x0F & param. 3 (bits to output) contains 0x1C - only bits 2 & 3 will be set!   The mask (0x0F) in this example allows only the 4 lower bits w/in that port to be output "high."   Thus - even though param. 3 sought to turn on bit_4 - it could not due to the mask w/in param. 2.
    • This method works across ALL ports - recall that each port is only 8 bits wide - choosing 255 as the mask enables all bits to be set.

    Biggest issue for those new to this API is the expectation that param. 3 set to 1 will turn on (any) bit.   (as it does w/in many (other) APIs)   That will work (only for bit_0 here.)   Again you must employ the "weighted bit value" - based upon bit's position w/in the byte - to output bit high.

    There's a similar mask w/in "reads" - armed w/this understanding your review of the Peripheral Driver User Guide should be faster & (one hopes) easier...