AT91SAM7S256->Interrupt through press a Button->doesn'

Hi,

i’m trying at the moment to execute a simple interrupt through a Button (Button2) while a LED is blinking, but nothing happens!

I’ve got the EK Boad from Olimex.

The button is connected with PA20 which is also IRQ0.

Would be great is someone have 2-3 minutes to have a look on m code, thanks!

Regards from cologne!

Tobi

main.c:


#include “AT91SAM7S256.h”

#include “board.h”

#include “delay.h”

#include “stdlib.h”

#include “string.h”

void button2irqhandler (void);

extern void LowLevelInit(void);

extern unsigned enableIRQ(void);

void LowLevelInit();

int main (void) {

// Set up the LEDs (PA0 - PA3)

volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; // pointer to PIO

data structure

pPIO->PIO_PER = LED_MASK | Button2; // PIO Enable Register -

allow PIO to control pins P0 - P2 and pin 19

pPIO->PIO_OER = LED_MASK; // PIO Output Enable Register -

sets pins P0 - P2 to outputs

pPIO->PIO_SODR = LED_MASK; // PIO Set Output Data

Register - turns off the two LEDs

// Select PA20 (pushbutton) to be IRQ function (Peripheral B)

pPIO->PIO_BSR = Button2;

// Set up the AIC registers for Button2

volatile AT91PS_AIC pAIC = AT91C_BASE_AIC; // pointer to AIC

data structure

pAIC->AIC_IDCR = (1<<AT91C_ID_IRQ0); // Disable IRQ0 interrupt

in AIC Interrupt Disable Command Register

pAIC->AIC_SVR[AT91C_ID_IRQ0] = // Set the Button2 IRQ0

handler address in AIC Source

(unsigned int)button2irqhandler; // Vector Register[30]

pAIC->AIC_SMR[AT91C_ID_IRQ0] = // Set the interrupt source

type and priority

(AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 0x4 ); // in AIC Source Mode

Register[30]

pAIC->AIC_ICCR = (1<<AT91C_ID_IRQ0); // Clear the IRQ0

interrupt in AIC Interrupt Clear Command Register

pAIC->AIC_IDCR = (0<<AT91C_ID_IRQ0); // Remove disable IRQ0

interrupt in AIC Interrupt Disable Command Reg

pAIC->AIC_IECR = (1<<AT91C_ID_IRQ0); // Enable the IRQ0

interrupt in AIC Interrupt Enable Command Register

enableIRQ();

while (1) {

Delay(500);

if ((pPIO->PIO_ODSR & LED1) == LED1) { // read previous state

of LED1

pPIO->PIO_CODR = LED1;

} else {

pPIO->PIO_SODR = LED1;

}

}

}


button2isr.c:


#include “AT91SAM7S256.h”

#include “board.h”

void button2irqhandler (void) {

volatile AT91PS_TC pTC = AT91C_BASE_TC0; // pointer to timer

channel 0 register structure

volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; // pointer to PIO

register structure

unsigned int dummy; // temporary

dummy = pTC->TC_SR; // read TC0 Status Register to

clear interrupt

if ((pPIO->PIO_ODSR & LED2) == LED2) {

pPIO->PIO_CODR = LED2; // turn LED2 (DS2) on

} else {

pPIO->PIO_SODR = LED2; // turn LED2 (DS2) off

}

}


unsigned enableIRQ(void)

{

unsigned _cpsr;

_cpsr = __get_cpsr();

__set_cpsr(_cpsr & ~IRQ_MASK);

return _cpsr;

}