SPI - A simple implementation
ARM processor
To get an opportunity to test our newly acquired SPI knowledge, we use a Saxo-L board. It
has an ARM7 processor (LPC2138) and a Cyclone FPGA (EP1C3), connected by a SPI bus.
The ARM is used as a SPI master, while the FPGA is used as a SPI slave. The Saxo-L ARM
processor has actually two SPI interfaces, one called SPI0, and a more advanced one called
SPI1/SSP. They are both equally easy to use. We are using SPI1/SSP on Saxo-L, as it is
pre-wired on the board.
SPI master - C ARM code
Using SSP is just a matter of initializing a few registers, and then writing/reading data to
send/receive automatically.
void main(void)
{
// initialize SSP
SSP0CPSR = 0x02; // SSP max speed
SSP0CR0 = 0x07; // SSP max speed, 8 bits
SSP0CR1 = 0x02; // SSP master mode
PINSEL1 = 0x2A8; // SSP mode for pins P0.17 to P0.20
while(1)
{
// send two bytes
SSP0DR = 0x55; // one nice thing about the SSP is that it has a 8-words deep
FIFO
SSP0DR = 0x54; // so here we write the data to be sent without worrying
// now wait until both bytes are sent
while(!(SSP0SR & 0x01));