Small question about GPIO function

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by zepedrowdp on Fri Apr 04 10:22:07 MST 2014

While I was studying the files regarding the GPIO on LPCOpen2.10 I became intrigued with the way the parameter pGPIO works. It seems to be a pointer to a structure and it's described on the briefs of the function's headers as "The base of GPIO peripheral on the chip".

I was expecting that in case you wanted to change the state of a pin on port2 you would used LPC_GPIO2, or in case of port1 LPC_GPIO1. Although, the functions only seem to work when you assign LPC_GPIO as the pGPIO. I found it odd, because when I took a look at #define of LPC_GPIO, it has the base address of GPIO0, and LPC_GPIO1 the base address of GPIO1, and so on...

For example:

If want to set the pin P[1]31, with this function:

* @briefSet an individual GPIO output pin to the low state
* @parampGPIO: The base of GPIO peripheral on the chip
* @paramport: GPIO Port number where pin is located
* @parampin: pin number (0..n) to set low
* @returnNone
* @noteAny bit set as a '0' will not have it's state changed. This only
* applies to ports configured as an output.
STATIC INLINE void Chip_GPIO_SetPinOutLow(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)

The expected code to write would be:

Chip_GPIO_SetPinOutLow(LPC_GPIO1, 1, 31);

But in fact it only works if you write:

Chip_GPIO_SetPinOutLow(LPC_GPIO, 1, 31);

Why does it happens?