I am using an AT91SAM7S64 eval board w/ IAR. I have configured the SPI in SLAVE mode as noted below. I can see DATA and CLK from an external micro (MASTER) driving in on a scope and I also see the NSSR bit toggle in the Status Register. However, my SPI_RDR is always 0!!! Cant figure out why???
Anyone know what may cause this? Please help! Thanks!
-Adi
Code:
//*----------------------------------------------------------------------------------
//* Function Name : SPI_init
//* Object : Initialize SPI in SLAVE mode
//* Input Parameters : none.
//* Output Parameters : none
//*----------------------------------------------------------------------------------
void SPI_init(void)
{//* Begin
//Setup Peripheral Multiplexing... I.e. tell PIO what pins do what...
AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA,
((unsigned int) AT91C_PA13_MOSI) |
((unsigned int) AT91C_PA12_MISO) |
((unsigned int) AT91C_PA14_SPCK) |
((unsigned int) AT91C_PA11_NPCS0), // Peripheral A
0); // Peripheral B
//Setup the Peripheral Clock
AT91F_SPI_CfgPMC();
//Setup Pin inputs/outputs
AT91F_PIO_CfgInput( AT91C_BASE_PIOA,
((unsigned int) AT91C_PA13_MOSI) |
((unsigned int) AT91C_PA14_SPCK) |
((unsigned int) AT91C_PA11_NPCS0)
);
AT91F_PIO_CfgOutput( AT91C_BASE_PIOA,
((unsigned int) AT91C_PA12_MISO));
//Setup SPI Mode Registers (Slave, Clock, etc...)
pSPI->SPI_MR=0;
//Setup SPI (# of bits/transfer, Clock Phase, and speed)
pSPI->SPI_CSR[0] =AT91C_SPI_BITS_8 | AT91C_SPI_NCPHA |((unsigned int) 0x02 << 8) ;
pSPI->SPI_TDR=0x00; // Perhaps needs to transmit first in order to receieve???
AT91F_SPI_Reset(pSPI);
AT91F_SPI_Enable(pSPI);
/*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main function
//* Input Parameters : none
//* Output Parameters : TRUE
//*----------------------------------------------------------------------------
unsigned char spiChar = 0x0;
int main( void )
//* Begin
{
// Initialize SPI
SPI_init();
//* Infinite loop
for(;;)
{
while(!(pSPI->SPI_SR & 1));
spiChar = pSPI->SPI_RDR & 0xff;
}// End for
}//* End