lpcware

reading input pin

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by cseb on Sun Nov 01 01:45:28 MST 2015
Hi,
I have trouble with reading a pin as input. I use the code below. I can only read the pin one time and even if its physical state changes , i can not read the change. In user manual its stated ("if an FIOPIN register is read, its bit(s) masked with 1 in the FIOMASK register will be read as 0 regardless of the physical pin state".)page122, but i can not solve this problem.



static LPC_GPIO_TypeDef (* const LPC_GPIO[5]) = { LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3, LPC_GPIO4  };

uint32_t GPIOGetValue (uint32_t portNum, uint32_t bitPosi)
{
    uint32_t val;
    LPC_GPIO[portNum]->FIOMASK = ~ (1 << bitPosi);
    val = LPC_GPIO[portNum]->FIOPIN;
    val = val >> bitPosi;
    LPC_GPIO[portNum]->FIOMASK = 0x00000000;
    return val;
}

Outcomes