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.

LM4F232H5QD INVERTING PIN

I was using pic microcontroler, but now i want migrate to ARM Cortex, due this i'm new in ARM world and i wanna change state of single pin

i get change state of pin like below

 

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2 );

  while (1){

           GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_2, GPIO_PIN_2);
           GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_2, 0);

    }

 

but i need read state of pin and inverting state like below

  while (1){

           GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_2, ! GPIO_PIN_2); //this code dont work  i try use GPIOPinRead but don't work too     

    }

how can i make this change ?

  • The ! operator is a logical NOT, not a bitwise NOT.  If you want to do a bit inversion, use the ~ operator.

    Additionally, GPIO_PIN_2 is just a bit mask, it's not the value read from a pin.  Since GPIO_PIN_2 is a true (non-zero) value, !GPIO_PIN_2 evaluates to false or zero.

    You could write code to invert the output at pin G2 as:

    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, ~GPIOPinRead(GPIO_PORTG_BASE, GPIO_PIN_2));

    or

    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, GPIOPinRead(GPIO_PORTG_BASE, GPIO_PIN_2) ^ GPIO_PIN_2);