LPC2148 Input pins

Hi,

I got a LPC2148 test board and the standard code exmaples are working perfect.

The only I can’t get to work properly is to check the value of a pin, that is set as input.

SCS=0x03;
FIO1DIR = 0x1E0000; //pin 1.17-1.20 as output
FIO1SET = 0x1E0000; //set pin 1.17-1.20 to 1

This is working properly.

But when I want to read the value of pin 1.16, which get its input of a external adc, it goes somehow wrong.

I tried it with a bitmask, but when I debug, the values are not correct.

FIO1PIN2 presents bit 0 p1.16… bit 7 1.23

if (FIO1PIN2&0x01) {...}

Should this work with a bitmask or is there a way just check one bit at a time.

I hope someone can help me.

Thanks in advance.

Maurice

I tried it too and got the same results, dont have time to dig into it right now.

I used the IO1PIN instead and was able to read it the pin properly.

FIO1PIN2 is not defined in the standard LPC214x.h header file, so the way you have defined it could be your problem. Instead, try using FIO1PIN and using the mask 0x10000.

if((FIO1PIN & 0x10000) != 0)
{
   <bit was set>
}
else
{
   <bit was false>
}

I do a similar operation in my tutorials for the nRF24L01 for the LPC2148 when I check for the IRQ pin status in the function bool nrf24l01_irq_pin_active() in nrf24l01.c. nrf24l01_IRQ_IOREGISTER is #define’d to FIO0PIN and nrf24l01_IRQ_PINMASK is #define’d to 0x8000 in nrf24l01.h. Check out my signature line for my website where you can find the tutorials if it might help you.

Thanks for your reply, all check out your website.

#define FIO1PIN2 (*(volatile unsigned char *)0x3FFFC036)

I already got it with FIO1PIN, like brennen said.

Thanks anyway.

If you check LPC214x.h as it is in my tutorials, I have defines for all of the byte-level registers added (i.e., FIO1PIN2, FIO0SET1, etc.). These have been tested (for the most part) and should work, and you are free to use them if you want in your own code.