AnsweredAssumed Answered

Quick Newbie Question about Syntax

Question asked by dramsay on May 3, 2011
Latest reply on May 5, 2011 by dramsay

Hey all, I've been digging around in the documentation and I'm having trouble finding an example of the syntax I need to get SPI recieve with my SHARC ADSP-21262 EZ Kit working (it's the master, and I've verified with a logic analyzer that the slave is sending things properly).

 

My ROVF bit is getting thrown, and in order to try and prevent this overwrites from happening, my plan was to read a bit when the SPISTAT RXS bit indicated that the buffer was full, then sit in a while loop until the RXS bit indicates that the buffer has emptied into a temporary int, and then write that bit to a value in an array.   Sends from the slave only occur when the SHARC writes (in my case writing 0xFFFF), and I have put all of this in a while loop to keep sending requests until the 6 values I'm expecting have been written.

 

 

It's not working- I think it's because of my syntax accessing the SPISTAT register in the if statement/while loop.  This is what I have (situated in the SPI Core Driven C code provided with the kit):  How can I fix it?  (Right now it's hanging after the first 0xFFFF write).

 

Thanks a million!

 

 

 

 

Here's the code:

 

 

/* SPI Control Registers                                  */
#define SPICTL  (0x1000)
#define SPIFLG  (0x1001)
#define SPIBAUD (0x1005)
#define TXSPI   (0x1003)
#define RXSPI   (0x1004)
#define SPISTAT (0x1002)

 

/*SPICTL bits                                             */
#define TIMOD1  (0x0001)  /* Use DMA for transfers        */
#define DMISO   (0x0020)  /* Disable MISO pin             */
#define MSBF    (0x0200)  /* Most Significant bit first   */
#define WL16    (0x0080)  /* SPI Word Length = 16         */
#define SPIMS   (0x1000)  /* SPI Master if 1, Slave if 0  */
#define SPIEN   (0x4000)  /* SPI Port Enable              */

 

/*SPIFLG bits                                             */
#define DS0EN   (0x0002)  /* use FLG1 as SPI device-select*/

 

/* Default Buffer Length */
#define BUFSIZE 36

 

/* Transmit Buffer */
int tx_buf[BUFSIZE]=   {0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
                        0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
                        0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
                        0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
                        0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
                        0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008
                        };

 

int rx_buf[6]= { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};

 

                       
/* Main code section */
main(){
int i;
int d;

 

/* Init SPI MASTER TX */
*(volatile int *)SPICTL = 0;
*(volatile int *)SPIFLG = 0;

 

/* set the SPI baud rate to CCLK/4*3000 (16.6KHz @ 200MHz)*/
     *(volatile int *)SPIBAUD = 3000;

 

/* Set up DAG registers */
*(volatile int *)SPICTL = DMISO|WL16|MSBF|SPIMS|SPIEN|TIMOD1;

 


/*Set up SPI CS as Flag1 */
*(volatile int *)SPIFLG = DS0EN;

 


/* Set up loop to transmit data */
for(i=0; i<sizeof(tx_buf); i++)
    {
    for (d=0;d<0x02FF;d++)
               asm("nop;");
              
   *(volatile int *)TXSPI=tx_buf[i];
  
    }

 

/* Set up loop to receive data */
i=0;

 


while(i<6)
    {
    for (d=0;d<0x02FF;d++)
               asm("nop;");
              
   *(volatile int *)TXSPI=0xFFFF;
  
       
           
    if((*(volatile int *)SPISTAT && 0x0020) != 0)   
        {
              
            int received = *(volatile int *)RXSPI;
          
            while(*(volatile int *)SPISTAT && 0x0020 != 0);   
       
               if (i==0)
                rx_buf[i++] = received;
            else if (rx_buf[i-1] != received)
                rx_buf[i++] = received;
      
       
          
        }
    }          
   
   
}

 

 

 

Also, by the way, the included SPI Core Driven code didn't properly work for me unless I added in a for loop delay in order to keep the chip select low for long enough.  Just something to double check and perhaps fix.  Thanks!

Outcomes