Using the SPI is straight forward.
Here is a sample of my init code and my read/write code.
You have to write 0xFF in order to Read.
Init:
I am using the CSAAT bit in order to keep CS active for multiple
reads and writes.
INIT()
{
AT91F_SPI_CfgPIO(); // sETUP pio for SPI interface
AT91F_PIO_CfgPullup(AT91C_BASE_PIOA, AT91C_PIO_PA14 |
AT91C_PIO_PA12); // Pull up the CLK PA14 and SDI PA12
AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC,
1 << AT91C_ID_SPI); // Enable the Peripheral Clock on PA14
//* Reset the SPI 1st
AT91F_SPI_Reset(SPI0);
//*Configure the SPI into Fixed Pheriperhal mode
AT91F_SPI_CfgMode (SPI0, AT91C_SPI_MODFDIS |
AT91C_SPI_PS_FIXED | AT91C_SPI_MSTR);
//*Set SPI_CSR0 for FRAM interface - Set CLK to MCK/4 =
11.9808 MHz - No delays
AT91F_SPI_CfgCs (SPI0, 0, // NPCS0
AT91C_SPI_NCPHA | AT91C_SPI_CSAAT | // Mode 0 & Chip Select
After transfer disabled
(AT91C_SPI_BITS & AT91C_SPI_BITS_8) | // mask & Bits per transfer
(AT91C_SPI_SCBR & (FRAM_CLK_SCBR << 8))); // mask & CLK=MCK/4
//*enable the SPI - NPCS0
AT91F_SPI_Enable(SPI0);
}
Here is my SPI routine
//*------------------------------
----------
//* \fn SPI_Byte
//* \brief transfer character and Receive a character if one is
available
//*------------------------------
----------
char SPI_Byte (const AT91PS_SPI pSPI, char character, unsigned int
cs_number, int last_xfer)
{
unsigned int value_for_cs;
char rx_char;
value_for_cs = (~(1 << cs_number)) & 0xF; //Place a zero among
a 4 ONEs number
// Wait for transmit data register to become available
while ( !(pSPI->SPI_SR & AT91C_SPI_TDRE) );
if (last_xfer)
{
pSPI->SPI_TDR = (value_for_cs << 16) | character |
AT91C_SPI_LASTXFER; // CS# | Character | Last xfer
}
else
{
pSPI->SPI_TDR = (value_for_cs << 16) | character; // CS# |
Character
}
// Wait for receive data register to indicate incoming data
while ( !(pSPI->SPI_SR & AT91C_SPI_RDRF) );
rx_char=((pSPI->SPI_RDR) & 0xff);
return (rx_char);
}
--- In AT91SAM7@AT91..., "at91sam7s" <at91sam7s@y...> wrote:
> I want to communicate with a SPI serial flash.
> I've seen enough code to initialize the SPI port.
> However, I can't find any sample code that will
> show me how to tx and rx bytes in page mode.
>
> In the AT91_CDROM, I see a file called :
> AT91M55800A-BasicSPI-GHS3_6-2_0.zip
>
> Can I re-use some of the code for the SAM7S64?
> Are the SPI registers the same?
> Thanks