Problem setting pin P2.0 as GPIO in LPC1768

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Problem setting pin P2.0 as GPIO in LPC1768

787 次查看
lpcware
NXP Employee
NXP Employee
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
0 项奖励
回复
2 回复数

486 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ngoncalves on Tue Apr 24 08:29:29 MST 2012
It was an hardware/human problem. I was reading the wrong pin, because I got confused with the markings on the processor. Three circles, but only one of them is the little one.....

Thanks
0 项奖励
回复

486 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Apr 24 08:28:02 MST 2012
The code you've posted is working without problems with my LPC1768 here after inserting it in new LPCXpresso project :eek:

So either you have a hardware problem or your project setup is wrong.

Perhaps you want to reduce your project and post it :rolleyes:
0 项奖励
回复