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 help with SPI in slave mode - SPI_RDR is always 0???
PostPosted: Thu Apr 27, 2006 1:43 am 
Offline

Joined: Mon Apr 17, 2006 10:38 pm
Posts: 5
Location: Clarksburg, MD
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



Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 10:36 pm 
Offline

Joined: Mon Apr 17, 2006 10:38 pm
Posts: 5
Location: Clarksburg, MD
ok. I figured it out. I had to set the POL and PHA appropriate to the Master for it to read.


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 1 guest


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: