I need to read 8 bit parallel data using an AT91SAM7S64. The issue I am having is of the 32 PIO bits, I can’t have the 8 bits together because of other perpherials in use.
// Here's the input pins for the 8 bit data
#define DATA0 (1<<0)
#define DATA1 (1<<1)
#define DATA2 (1<<26)
#define DATA3 (1<<27)
#define DATA4 (1<<28)
#define DATA5 (1<<29)
#define DATA6 (1<<30)
#define DATA7 (1<<31)
#define DATA_MASK (DATA0|DATA1|DATA2|DATA3|DATA4|DATA5|DATA6|DATA7)
I set up the PIO like this:
AT91C_BASE_PMC->PMC_PCER = (1<<AT91C_ID_PIOA); // Turns on the perpherial clock
AT91C_BASE_PIOA->PIO_PER = DATA_MASK; // Enables DATA pins
AT91C_BASE_PIOA->PIO_ODR = DATA_MASK; // Makes DATA pins inputs
AT91C_BASE_PIOA->PIO_PPUDR = DATA_MASK; // Disables pullups on DATA pins
Now I read the PIO_PDSR register and mask it like this:
int a;
a = AT91C_BASE_PIOA->PIO_PDSR & DATA_MASK;
Now I have register “a” with 32 bits of data like this 0bxxxxxx111111111111111111111111xx where “x” is my 8 bits of incoming data and the only data I want. My question is what is the fastest way (least amount of instruction cycles) to turn this data into a CHAR? I have tried several ways using several variables and shifting it around but it’s becoming more complicated than I think it should be and it’s not working. Thanks in advance for any replies!