AT91SAM7S-EK (256) SPI Configuration + Usage Problems

Hi there,

I have not used SPI before so I am doing a lot of learning now, but after about 5 full days of trying to get the SPI working with an NVRAM Chip (FM25CL64) I am running out of ideas. I am using a AT91SAM7S-EK with the AT91SAM7S256 processor. I have configured the DBGU UART port to print data to HyperTerminal to see what is going on.

Below is the code. Note: Using an oscilloscope to monitor any of the pins (MOSI, SPCK etc) I do not see any traces. I don’t understand what is going on. Also, I know the method of configuring the pins works as it works fine for the USART0 and push buttons/leds I am using. That is what the call to PIO_Config does.

Initiation code:

void SpiInit(void)

{

DBGUprint(“Initializing SPI…\n\r”);

PMC_EnablePeripheral(AT91C_ID_SPI); // Enable the clock of the SPI

PIO_Configure(spitransfer, PIO_LISTSIZE(spitransfer));

AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS |AT91C_SPI_SWRST; //Reset

//SPI_Enable(AT91C_BASE_SPI);

SPI_Configure(AT91C_BASE_SPI,

AT91C_ID_SPI,

AT91C_SPI_MSTR |

AT91C_SPI_PS_FIXED |

AT91C_SPI_MODFDIS |

SPI_PCS(0)

//AT91C_SPI_PCS_NPCS0 //| Not sure about this one - I’ve modified it to be PCS = xxx0 - See page 280 of Datasheet

// AT91C_SPI_PCSDEC_DISABLE

);

// DBGUprint(“2. SPI Configured\n\r”);

//Configure SPI Chip Select Register

SPI_ConfigureNPCS(AT91C_BASE_SPI,

0, // NPCS0

AT91C_SPI_NCPHA | // Mode 0 (CPOL=0,CPHA=0)

(64 << 8) | // SCBR: SPCK=MCK/SCBR //8 or 64

(0 << 16) | // DLYBS: Delay from NPCS to SPCK in MCK cycles

(0 << 24) | // DLYBCT: Delay between consec xfers

AT91C_SPI_BITS_8 | // 8-data bits

AT91C_SPI_CSAAT //The current Chip Select is programmed to remained Active After Transfer

);

// DBGUprint(“3. NPCS Configuredn\r”);

SPI_Enable(AT91C_BASE_SPI);

// DBGUprint(“5. SPI Enabled\n\r”);

DBGUprint(“SPI Initialization Complete\n\n\r”);

}

test code:

void testfunction()

{

char temp[100] = “123456789123456789123456789123456789”;

char testdata[15] = “HELLO THERE”;

int size = 0;

SPI_Enable(AT91C_BASE_SPI); //ENABLE SPI

NVRAM_WriteProtectDisable();

DBGUprint("\n\rData is: ");

DBGUprint(temp);

DBGUprint(“\n\r”);

size = strsize(testdata);

NVRAM_WriteDataBlock(testdata, size, 0x0000);

NVRAM_ReadDataBlock(temp, size, 0x0000);

DBGUprint("\n\rData is: ");

DBGUprint(temp);

DBGUprint(“\n\r”);

}

from the DBGU port I expect to see:

Data is: 123456789123456789123456789123456789

Data is: HELLO THERE3456789123456789123456789

However I see:

Data is: 123456789123456789123456789123456789

Data is: 3456789123456789123456789

This happens even if the pio_config line is gotten rid of, or if i change the number in the spi_confignpcs arguments to 1,2,3, or 4. I literally have no idea what is going on.

After much checking i feel that i have set everything up right and i should be seeing at least a clock signal on teh SPCK but yet I see nothing.

I look forward to hearing any thoughts.

Kind Regards,

Phil