This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPI communication protocol stellaris launchpad/

Howdy, 

I have a half duplex spi device that i am setting up my spi protocol to run on my stellaris using the ssi library. I need to set it up so that the stellaris does not read during transmission of data to the device.

the protocol is like this

The code i Wrote for write is as follows. Mind the conversion from char to long for data put then back to char from long

int readfromspi_serial
(
    unsigned short       headerLength,
    const unsigned char *headerBuffer,
    unsigned long        readlength,
    unsigned char       *readBuffer
)
{
    int i=0;
    unsigned char x2;
    unsigned long y1;

    //Enable The Slave Select pin for this device
    GPIO_PORTF_DATA_R &= ~(0x04);

	for(i=0; i<headerLength; i++)
	{
		
		y1 = *(headerBuffer + i);
		SSIDataPut(SSI0_BASE, y1);
		while(SSIBusy(SSI0_BASE))
		{
		}
		//need to make sure to ignore reads during this time
	}

	for(i=0; i<readlength; i++)
	{
	    x2 = *(readBuffer + i);
	    y1 = (long) x2;

      //SSIDataGet(unsigned long ulBase, unsigned long *pulData)
	   SSIDataGet(SSI0_BASE, &y1);
	   while(SSIBusy(SSI0_BASE))
	   {
	   }
	   x2 = (char) y1;
	   *(readBuffer + i) = x2;
        }

	//Disable slave select pin
	GPIO_PORTF_DATA_R |= 0x04;



    return 0;
} // end readfromspi()

Thanks for any help!

  • Sean,

    I don't quite understand your question. So you want to ignore the received data from the slave? If so, just read and discard so you won't get an overflow. Is there a reason this won't work?
  • You are right I really didn't state my question. I am new to the spi protocol and am uncertain about how the ssi functions work. I am not really sure how to ignore/read during the wait time. Should I put a data get right after my data put in order to clear the buffer?
  • Hi Sean,

    So generally speaking, the way SPI (SSI) works is bits are shifted out from the master on MOSI and, simultaneously, data is shifted in on MISO. So, you could simply read the SSI receive buffer after all of the data is shifted out. The key is to gate the read so that it doesn't occur until after the SSI has finished sending the data. You could either poll a TX complete flag or setup an interrupt based system that fires an interrupt when the Tx is done then read the received data into a dummy variable never to be used again.