Hi
To set up the SPI in master mode (eg. SPI0 at 2MHz) you can do the following:
// first configure the ports for SPI and CS line
PMC_PCER = PIOA; // power up port A
PIO_ASR_A = (SPI_MOSI_0 | SPI_MISO_0 | SPI_CLK_0);
PIO_PDR_A = (SPI_MOSI_0 | SPI_MISO_0 | SPI_CLK_0);
PIO_PER_A = (CS_OUTPUT);
PIO_SODR_A = (CS_OUTPUT);
PIO_OER_A = (CS_OUTPUT);
PMC_PCER = SPI0; // enable clocks to SPI
SPI_MR_0 = (SPI_MSTR | MODFDIS | SPI_CS_0); // master mode with no clock divider and control defined by CS0 configuration {27}
SPI_CSR0_0 = (SPI_CPOL | SPI_8_BITS | (((MASTER_CLOCK + 2000000/2)/2000000)<<8));
SPI_CR_0 = SPIEN; // enable SPI
To send one byte of data do something like the following:
PIO_CODR_A = CS_OUTPUT; // assert CS
Dummy = SPI_RDR; // clear rx buffer
SPI_TDR_0 = byte_to_send; // send a byte
while (!(SPI_SR_0 & SPI_RDRF)) {}; // wait until tx byte has been sent and rx byte has been completely received
PIO_SODR_A = CS_OUTPUT; // negate CS
Regards
Mark
http://www.uTasker.com