using the SPI peripheral

Questions on control of serial busses
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

using the SPI peripheral

Post by YahooArchive »

I want to use the hardware serial bus so I don't run the risk of geting
"locked-up" with the software bus.
The main killer problem is the total lack of a clock line?
I'm a fairly newbe and feel lost by this . . . Help?



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: using the SPI peripheral

Post by YahooArchive »

You can enable the SPI hardware by direct reads to those registers, details in
the NXP user manual.

The basic steps are

turn on the device in SCB_PCONP
enable the SPI connection to the pins in a PINSEL register

then start programing the SPI
typically you enable it, chose the mode, and clock rate (the clock is
automatically generated for you based on the 15 MHz PCLK)
write to the SPI FIFO
either poll for done or setup an interrupt

Anyone have a code example out there?

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: using the SPI peripheral

Post by YahooArchive »

For more information and code examples see the NXP Application Notes:

AN10369: UART/SPI/I2C code examples
AN10406: Accessing SD/MMC card using SPI on LPC2000

http://ics.nxp.com/support/documents/mi ... pe=appnote

Regards,
Chris Burrows

Astrobe v3.2: LPC2xxx Oberon-07 Development System
http://www.astrobe.com

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: using the SPI peripheral

Post by YahooArchive »

I also cant seam to get hardware spi to work. this is the code im trying

SCB_PCONP |= (1<<8); // enable spi hardware
PCB_PINSEL0 |= 0x5500; // configure SPI0 pins
SPI_SPCCR = 0x8; // SCK = 1 MHz, counter > 8 and even
SPI_SPCR = 0x20; // Master, no interrupt enable


WAIT(100);

while(1)
{
SPI_SPSR = 0;
// send data
SPI_SPDR = 0x9F;
// wait for transfer to be completed
while( 0==(SPI_SPSR & 0x80) )
{
//WAIT(100);
//printf("%x \r",SPI_SPSR);
}

break;
}

i cant see what im missing? id expect it to send the byte and just drop out the
while loop. but it never drops out
Last edited by YahooArchive on Mon Feb 11, 2013 1:23 am, edited 1 time in total.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: using the SPI peripheral

Post by YahooArchive »

solved my problem, the SSEL pin has to be held high!

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: using the SPI peripheral

Post by YahooArchive »

Iv adapted a Dataflash AT45DBXX1D library that was written for the Arduino to
work for the arm lpc21xx using hardware SPI

It seams to work great :), email me if you want a copy, this Atmel Dataflash is
a great little chip :)

russdx@dsl.pipex.com

Post Reply