Amtel at91sam7s256 example needed!

Guest #1172087
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*
Guest #1172088
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*

Reply

A question of your own? This thread is over 19 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.