Cannot configure GPIO for input in LPC1769

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cannot configure GPIO for input in LPC1769

2,209 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lucasmf004 on Thu Sep 10 21:11:14 MST 2015
Hi! I'm writting you because I can't configure the GPIO  function for LPC1769 with LPCOpen. I only want to have as input the pins number 15,16,17,18,23,24,26,26 to use a matrix board, so I need to have them in high state when nothing is connected. My configuration code is the following:


#definePIN_PortLPC_GPIO
#defineTECLADO_Mask0x7878000


void Pin_Init(void)
{

Chip_GPIO_Init(PIN_Port);
Chip_GPIO_SetPortMask(PIN_Port, 0, TECLADO_Mask);
Chip_GPIO_SetDir(PIN_Port, 0, TECLADO_Mask, 0);


}


//This function is to know if the port is well configured. When I ground the pin number 15, for example, it should take change.

void Lee_Pin(void)
{
uint32_tLectura = 0;

Lectura = Chip_GPIO_ReadValue(PIN_Port, 0);

}

I hope you could help me with this. Any one has an example of how configure the GPIO port (not the one that comes with LPCExpresso)


Pd: Sorry for miy english, I'm not a native speaker, I'm from Argentina.


Labels (1)
0 Kudos
Reply
4 Replies

1,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lucasmf004 on Sat Sep 12 16:14:51 MST 2015
Thank you so much R2D2!! I'm testing it and by the moment it's working fine, I was understanding some functions from de iocon_17xx_40xx.h file when I saw your reply. It helped me a lot!.. I'll tell you how worked the matrix board in an few days!
0 Kudos
Reply

1,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Sep 11 12:34:51 MST 2015

Quote: lucasmf004
... do you know how can I set it to Pull-Up ??



Change PINSEL and PINMODE register with Chip_IOCON_PinMux() 

#include "board.h"
#include <cr_section_macros.h>

//input pins
#define INPUT_PINS((1<<15)|(1<<16)|(1<<17)|(1<<18)|(1<<23)|(1<<24)|(1<<25)|(1<<26))

//input
volatile uint32_t input, input_old;

//init
void app_init(void)
{
 Chip_GPIO_Init(LPC_GPIO);
 //set P0[23] and P0[26] to GPIO (all other pins are GPIO & pullup already)
 [color=#f00]Chip_IOCON_PinMux(LPC_IOCON, 0, 23, IOCON_MODE_PULLUP, IOCON_FUNC0);[/color]
 Chip_IOCON_PinMux(LPC_IOCON, 0, 26, IOCON_MODE_PULLUP, IOCON_FUNC0);
 //set mask
 Chip_GPIO_SetPortMask(LPC_GPIO, 0, ~INPUT_PINS);//enable mask bits with 0
 //set to input
 Chip_GPIO_SetPortDIR(LPC_GPIO, 0, INPUT_PINS, 0);//set to input
}

int main(void)
{
 SystemCoreClockUpdate();
 Board_Init();
 Board_LED_Set(0, true);
 app_init();//app init
 input = Chip_GPIO_GetMaskedPortValue(LPC_GPIO, 0);//get masked port
 input_old = input;//store it
 volatile static int i = 0 ;
 while(1)//endless loop
 {
  i++;
  input = Chip_GPIO_GetMaskedPortValue(LPC_GPIO, 0);//get masked port
  if(input != input_old)//inputs changed
  {
   input_old = input;//store changed inputs
   LPC_GPIO[0].MASK &= ~(1<<22);//add LED mask bit
   Board_LED_Toggle(0);
   LPC_GPIO[0].MASK |= (1<<22);//remove LED mask bit
  }//end inputs changed
 }//end endless loop
 return 0 ;
}

0 Kudos
Reply

1,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lucasmf004 on Fri Sep 11 12:27:46 MST 2015
Thanks R2D2 for your help I followed your suggestion and it worked, but the pin value is not 3.3 and when I read it is equal to 0, do you know how can I set it to Pull-Up ?? My new configuration function is:

void Pin_Init(void) {

uint32_t PortDir_State = 0, Lectura=0;
uint32_t TECLADO_NO_Mask;

TECLADO_NO_Mask = ~TECLADO_Mask;

/* ESTA CONFIGURACION ESTÁ BIEN!!  */

Chip_GPIO_Init(PIN_Port);
Chip_GPIO_SetPortDIR(PIN_Port, 0, TECLADO_Mask,false);
Chip_GPIO_SetPortDIR(PIN_Port, 0, TECLADO_NO_Mask,true);


Lectura = Chip_GPIO_ReadValue(PIN_Port, 0);
PortDir_State = Chip_GPIO_GetPortDIR(PIN_Port, 0);
}
0 Kudos
Reply

1,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Sep 11 00:08:18 MST 2015
Probably you don't want to set pin 126320640 of Port 0 as input 

So you shouldn't use the pin function

Chip_GPIO_SetDir()


which is setting pin (1 << 0x7878000)...

There's a port function, which is doing what you want:

 Chip_GPIO_SetPortDIR(PIN_Port, 0, INPUT_Mask, 0);
0 Kudos
Reply