Hello all
i need to check if pin is low or high on the lpc2106 board (GNUARM).
I have set it as input and gpio
now
(IOPIN&0x08000000)
should return either 0 if pin low or 0x08000000 if pin high
so testing for these should tell me the value. but its not working for me!
what am i doing wrong here
What I usually do is test for zero (== 0) or for not zero (!= 0) instead of testing for the exact bit you ANDed with.
Is IOPIN defined as a volatile variable?
Is the pin configured as GPIO and as input?
Did you configure it correctly (proper IOSEL register)?
Is this pin some kind of special pin?
i havent got the full code at home but it looks somethinglike this:
#define PIN 0x08000000
#define CHECKPIN (IOPIN&PIN)
for (t=0;t<totaltime && CHECKPIN;++t){
no_operation;
}
the code neededs to wait till PIN goes from high to low or until time = totaltime
but the loop never stop for pin going low but it works for time.
i tried
for (t=0;t<totaltime && !CHECKPIN;++t){
no_operation;
}
just in case and it worked for pin being high. whats happening is that it always reads PIN as high even when its low and i confirm its going low using oscilloscope.
What do you have hooked up to this pin externally? Can you hook up either your positive supply rail (probably 3.3V) or ground and make sure that you’re reading the correct value at the IOPIN register? If you can’t read that, then you are not setting up your pin correctly. I would check this first (if you haven’t already).
Also, are you using a header file (something like lpc2106.h) that contains the register definitions for your micro? You might want to check the define for IOPIN and make sure it’s there and is correct.
it turns out it was a dry soder joint. found it out thanks to you guys
regards
TK
proc
April 15, 2008, 4:05pm
6
Hello everyone; I am new in ARM and I also am not able ta ask an input state of a portpin if it’s high or low
Setting an output works fine with AT91C_BASE_PIOB->PIO_SODR=AT91C_PIO_PB19;
but the inputstate does not change if I press the joystick on my SAM-EK-Board.
May be anyone can correct my code so that PA23-joystick-change is detected :
#define AT91_CAST(a) (a)
typedef volatile unsigned int AT91_REG;// Hardware register definition
#define AT91C_BASE_PIOB (AT91_CAST(AT91PS_PIO)0xFFFFF600) // (PIOB) Base Address
typedef struct _AT91S_PIO {
AT91_REG PIO_PER; // PIO Enable Register
AT91_REG PIO_PDR; // PIO Disable Register
AT91_REG PIO_OER; // Output Enable Register
AT91_REG PIO_ODR; // Output Disable Registerr
AT91_REG PIO_OSR; // Output Status Register
AT91_REG PIO_IFDR; // Input Filter Disable Register
AT91_REG PIO_SODR; // Set Output Data Register
AT91_REG PIO_CODR; // Clear Output Data Register
AT91_REG PIO_ODSR; // Output Data Status Register
AT91_REG PIO_PDSR; // Pin Data Status Register
AT91_REG PIO_ASR; // Select A Register
AT91_REG PIO_OWDR; // Output Write Disable Register
} AT91S_PIO, *AT91PS_PIO;
#define AT91C_PIO_PA23 (1 << 23) // Pin Controlled by PA23
#define AT91C_BASE_PIOA (AT91_CAST(AT91PS_PIO) 0xFFFFF400) // (PIOA) Base Address
int main(void)
{
int test=0;
volatile unsigned long pio_pdsr = AT91C_BASE_PIOA->PIO_PDSR;
volatile AT91S_PIO * pPIO = AT91C_BASE_PIOA; /* Global Pointer to PIO */
AT91C_BASE_PIOA->PIO_ODR =AT91C_PIO_PA23; /* Set the PIO line in input */
pPIO->PIO_PDR=AT91C_PIO_PA23;
AT91C_BASE_PIOB->PIO_ASR = AT91C_PIO_PA23; //Pin Enable Register
AT91C_BASE_PIOB->PIO_PDR = AT91C_PIO_PA23; //Pin Disable Register (set pin in peripheral mode)
AT91C_BASE_PIOB->PIO_ODR = AT91C_PIO_PA23; //Output Disable Register
AT91C_BASE_PIOB->PIO_PER = AT91C_PIO_PA23; //Pin Enable register
for(;;){
if((pPIO->PIO_ODSR & AT91C_PIO_PA23)!= AT91C_PIO_PA23)
//printf("Pin has changed");
}
}
Help would be very apreciated and surely would help other newbies …
You should read the PIO_PDSR register in order to read an input line. The PIO_ODSR register is the output status register.
regards
proc
April 16, 2008, 6:51am
8
Thank you; I really should read any AT91SAM7x for dummies (did not yet find a simple tutorial…)
With
int inport=0;
for(;;){
inport=((v->PIO_PDSR)&AT91C_PIO_PA23);
printf("%d\r\n",inport);
}
I really can see the port-changings now.