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  [ 2 posts ] 
Author Message
 Post subject: Need to understand SPI programming
PostPosted: Fri Mar 12, 2010 12:39 am 
Offline

Joined: Fri Mar 12, 2010 12:28 am
Posts: 5
I was trying to interface an SPI peripheral using my AT91SAM7S256-EK. However I couldn't understand the example codes because all they have is interfacing with a SD/MMC reader.

I want to ask for assistance on interfacing my device, especially on the initialization part.

I am using Keil uVision as my IDE.

Thanks.


Top
 Profile  
 
 Post subject: Re: Need to understand SPI programming
PostPosted: Fri Mar 12, 2010 3:46 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

SPI use on the SAM7 is quite straightforward. Below is a general configuration and then an example transmission and reception:

Code:
POWER_UP(SPI1 | PIOA);                         // enable clocks to SPI1 in PMC and Port A due to CS line
PIO_BSR_A = (SPI_MOSI_1B | SPI_MISO_1B | SPI_CLK_1B);
PIO_PDR_A = (SPI_MOSI_1B | SPI_MISO_1B | SPI_CLK_1B); // enable SPI pins
PIO_PER_A = (SPI_CS0_1B);                      // configure CS0 for SW control
PIO_SODR_A = (SPI_CS0_1B);
PIO_OER_A = (SPI_CS0_1B);

SPI_MR_1 = (SPI_MSTR | MODFDIS | SPI_CS_0);    // set SPI mode
SPI_CSR0_1 = (SPI_CPOL | SPI_8_BITS | (((MASTER_CLOCK + 6000000/2)/6000000) << 8)); // set speed 6MHz
SPI_CR_1 = SPIEN;                              // enable

PIO_CODR_A = SPI_CS0_1B;                       // assert CS line

SPI_TDR_1 = ucCommand;                         // send a byte
while (!(SPI_SR_1 & SPI_RDRF)) {};             // wait until tx byte has been sent and rx byte has been completely received
ucRxData = SPI_RDR_1;                          // read the returned byte

PIO_SODR_A = SPI_CS0_1B;                       // negate CS line


This is from the uTasker project. This may help you to use the SPI and the chip generally. (SPI use in the project includes SD card, SPI FLASH devices and LCD - eg. Nokia LCD on the Olimex boards) Full support at http://www.utasker.com/forum/index.php

Regards

Mark

www.uTasker.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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: