EmbDev.net

Forum: ARM programming with GCC/GNU tools Amtel at91sam7s256 example needed!


von Kam (Guest)


Rate this post
useful
not useful
Hi all,

I'm having a real pain in the ass trying to just READ a button input
from the Olimex at91sam7s256 proto board!

Here is the simple code!

volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;     // pointer to PIO data
structure

#define output_low(mask)    (pPIO->PIO_CODR=mask)
#define output_high(mask)   (pPIO->PIO_SODR=mask)
#define input(mask)         (pPIO->PIO_PDSR & mask)
//#define input(mask)         (pPIO->PIO_ODSR & mask)

#define HIGH    1
#define LOW     0

int main()
{
    int x;

    LowLevelInit();

    // Set up the LEDs
    pPIO->PIO_PER=LED_MASK|SW_MASK;     // bits 17,18 | 19,20
    pPIO->PIO_OER=LED_MASK;             // bits 17, 18
    pPIO->PIO_SODR=LED_MASK;            // bits 17, 18

    pPIO->PIO_ODR=SW_MASK;
    pPIO->PIO_PER=SW_MASK;


    // turn off LEDs
    output_low(LED1);
    output_low(LED2);

    while(1)
    {
        if(input(SW1)!=LOW)
        {
            output_high(LED1);
            output_low(LED2);
        }
        else
        {
            output_low(LED1);
            output_high(LED2);
        }
    }

    while(1);

    return 0;
}


Any thoughts?!

~Kam (^8*

von Kam (Guest)


Rate this post
useful
not useful
Got it!

I was missing the following line in the init...

    pPMC=AT91C_BASE_PMC;

    //enable the clock of the PIO
    pPMC->PMC_PCER = 1 << AT91C_ID_PIOA;


~Kam (^8*

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.