Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Basic example for setting up SPI needed
PostPosted: Fri Oct 17, 2008 1:28 pm 
Offline

Joined: Thu Oct 16, 2008 2:26 pm
Posts: 1
Hi!

I'm completely new to programming ARM7, and could need some help.

Does anyone know of a good and very basic example on how to set up my AT91SAM7S64-EK in SPI master mode, and how to send SPI data to my slave (in this case a PLL with SPI interface).

//mad_cow


Top
 Profile  
 
 Post subject: Re: Basic example for setting up SPI needed
PostPosted: Wed Oct 29, 2008 11:29 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
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


Top
 Profile  
 
 Post subject: Re: Basic example for setting up SPI needed
PostPosted: Fri Oct 31, 2008 6:16 pm 
Offline
User avatar

Joined: Fri Feb 13, 2004 7:53 pm
Posts: 329
Hello,
you have softpack available and an app. note.

http://www.at91.com/New/Controleurs/cVisualisation.php?idVisualisation=449

http://www.atmel.com/dyn/products/app_notes.asp?family_id=605#Communication%20Modules

Then pick up the following app. note and source code.
Using the Serial Peripheral Interface with AT91SAMxx Devices


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: