lpcware

Problem setting pin P2.0 as GPIO in LPC1768

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by ngoncalves on Tue Apr 24 07:21:15 MST 2012
Hi,


I am using the following code to set pins P2.0 to P2.4 as outputs and set their value:


uint8_t pinsel = 0 ;
uint8_t pin    = 0 ;

// P2.0
LPC_PINCON->PINSEL4 &= ~(3 << pinsel) ;
LPC_GPIO2->FIODIR0  |=  (1 << pin) ;
LPC_GPIO2->FIOSET0 |= (1 << pin) ;
delay(25) ;
LPC_GPIO2->FIOCLR0 |= (1 << pin) ;


// P2.1
pinsel += 2 ;
pin++ ;
LPC_PINCON->PINSEL4 &= ~(3 << pinsel) ;
LPC_GPIO2->FIODIR0  |=  (1 << pin) ;
LPC_GPIO2->FIOSET0 |= (1 << pin) ;
delay(25) ;
LPC_GPIO2->FIOCLR0 |= (1 << pin) ;

// P2.2
pinsel += 2 ;
pin++ ;
LPC_PINCON->PINSEL4 &= ~(3 << pinsel) ;
LPC_GPIO2->FIODIR0  |=  (1 << pin) ;
LPC_GPIO2->FIOSET0 |= (1 << pin) ;
delay(25) ;
LPC_GPIO2->FIOCLR0 |= (1 << pin) ;

// P2.3
pinsel += 2 ;
pin++ ;
LPC_PINCON->PINSEL4 &= ~(3 << pinsel) ;
LPC_GPIO2->FIODIR0  |=  (1 << pin) ;
LPC_GPIO2->FIOSET0 |= (1 << pin) ;
delay(25) ;
LPC_GPIO2->FIOCLR0 |= (1 << pin) ;

// P2.4
pinsel += 2 ;
pin++ ;
LPC_PINCON->PINSEL4 &= ~(3 << pinsel) ;
LPC_GPIO2->FIODIR0  |=  (1 << pin) ;
LPC_GPIO2->FIOSET0 |= (1 << pin) ;
delay(25) ;
LPC_GPIO2->FIOCLR0 |= (1 << pin) ;


I am following the datasheet, as far as I cant tell, but only P2.2 to P2.4 are actually set as GPIO's.

For some reason, in debug the processor registers show P2.0 and P2.1 being properly setup as GPIO (and the value is changing according to LPC_GPIO2->FIOPIN0), but there is no change on the physical pins (measuring with an oscilloscope).

I tried disabling the other two peripherals that use these pins (USART1 and PWM1) without success. Is there something I am not doing correctly ?

Nelson

Outcomes