There is sample code all over the Internet - try Google!
Some of the very best code is at www.jcwren.com/arm http://www.jcwren.com/arm
It is written for an LPC2148 but the SPI interface is identical.
The code I use is simple:
#include "LPC21xx.h"
#include "spi.h"
/*
* P0.4 => SCK connect to AD7327 SCLK - Pin 20
* P0.5 => MISO connect to AD7327 DOUT - Pin 18
* P0.6 => MOSI connect to AD7327 DIN - Pin 2
* P0.7 => SSEL connect to AD7327 CS' - Pin 1
*/
#define SSEL (1 << 7)
#define SPI_SPIE (0x00000080)
#define SPI_LSBF (0x00000040)
#define SPI_MSTR (0x00000020)
#define SPI_CPOL (0x00000010)
#define SPI_CPHA (0x00000008)
#define SPI_BitEnable (0x00000004)
#define SPI_Bits (0x00000000)
#define SPI_SPIF (0x00000080)
#define SPI_DIVIDER (8)
/*
* Set up SPI0 as a master with CPOL = 1, CPHA = 0 and 16 bit transfers.
* Force P0.7 to GPIO, set it for output and set it high
*/
void SPI0_init(void)
{
PINSEL0 |= 0x00001500;
PINSEL0 &= ~0x0000C000;
IO0SET = SSEL;
IO0DIR |= SSEL;
S0SPCR = SPI_MSTR | SPI_CPOL | SPI_BitEnable | SPI_Bits;
S0SPCCR = SPI_DIVIDER;
}
/*
* Send value to ADC and return value shifted in.
*/
unsigned short SPI0_Send(const unsigned short value)
{
IO0CLR = SSEL;
S0SPDR = value;
while (!(S0SPSR & SPI_SPIF))
;
IO0SET = SSEL;
return (S0SPDR);
}
It's up to you to get the clock divider right. I believe the core clock
for my project is 60 MHz.
Richard