0

I'm using LPC2368 wherein I have got to read the pin status if it is pressed or not? In arm7 I have connected that pin(which I have to monitor) to EINT2. I'm confused with pinsel section & how do i come to know if the key is pressed or not? I have used FIO2PIN and stored it in some variable

x = FIO2PIN;

then checked condition:

if(x == ((IN_Tamper >> 12) & 0X1) == 1)

wherein IN_Tamper is 0X1000;

Ross
  • 1,313
  • 4
  • 16
  • 24
YMJ
  • 154
  • 1
  • 2
  • 7
  • That boolean logic seem a bit weird. Read the FIOPIN into X and just AND it with the mask value for the EINT2 pin. The result will be 0 or not 0, depending on pin state. Also, like @TurboJ says, more stuff - what do you do with the PINSEL registers? – Martin James Jul 13 '13 at 14:46
  • Note that your question is very specific to the LPC2xxx MCU. ARM7 defines only the processor core and does not include GPIO or interrupt controller (or any peripherals) - the answer for ARM7 devices from other vendors will be different - you should perhaps change the title of the question. – Clifford Jul 13 '13 at 20:00
  • The whole point of `IN_Tamper` is so that you don't need to 'know' that it is bit 12 and avoid a 'magic number'. Right shifting it by 12 rather misses the point. You should therefore test `(x & IN_Tamper) != 0` – Clifford Jul 14 '13 at 07:04
  • Having connected the switch to EINT2 it would perhaps make sense to use an interrupt handler - otherwise EINT2 is irrelevant and its just a GPIO issue. You have not actually stated what happens or whether this code works or not. – Clifford Jul 14 '13 at 07:09
  • This is probably relevant: http://www.keil.com/forum/17762/, and this: http://read.pudn.com/downloads65/sourcecode/embed/231658/LPC23xx_24xxSampleSoftware.beta1/Keil/EXTINT/extint.c__.htm – Clifford Jul 14 '13 at 07:40
  • Also http://www.lpcware.com/content/nxpfile/sample-code-bundle-lpc23xxlpc24xx-peripherals-using-keils-%CE%BCvision – Clifford Jul 14 '13 at 07:53
  • Typically to get a GPIO to work on a device like this, you have to have powered, clocked, and direction configured the GPIO port. Then you have to define a pointer to a volatile data type, often of an explicitly allowed width (it may be mandatory to access it as 16 bit, or as 32 bit depending on the hardware). There's a lot to get wrong, so if you can find manufacturer example code which does the configuration, and a header file with pointer defines for the ports to start from that is going to be a shorter path than working out the requirements from the data sheet. – Chris Stratton Jul 14 '13 at 14:17
  • I did it my self as folloing code – YMJ Jul 15 '13 at 11:34
  • DIR_IN_TAMPER; x = FIO2PIN & TAMPER_PIN; x = FIO2PIN & TAMPER_PIN; if((x & (1<<12) !=0)) BUZZER_ON else BUZZER_OFF wherein IN_TAMPER = 0x00001000; – YMJ Jul 15 '13 at 11:35
  • used it twice b'z I wanted to check what if I don't press key will value of x changes?? so used it twice.. thank you then too!! – YMJ Jul 15 '13 at 11:36
  • @ Clifford ya I have used EINT0 as GPIO. but before I was committing mistake of using it as interrupt pin. my code is working perfectly. thank you!! – YMJ Jul 15 '13 at 11:56

0 Answers0