Skip to main content
pranathi1091
Associate III
March 5, 2013
Question

SPI Sends Dummy bytes

  • March 5, 2013
  • 1 reply
  • 838 views
Posted on March 05, 2013 at 14:32

Hello All,

I am using STM32F207VC. I have problem while sending data to slaves.

I send a packet of data for example 0x01,0x02,0x03,0x04,0x05,0x06.

While sending these packets SPI sends 0x00 in between anyof these data and my actual data is skipped.So My Slave doesnt understand what I am sending and its not responding.

Could any one pls let me know what could be the problem. I am stuck with this since last 2 days.

Here is my code

uint8_t SPIWrite(uint8_t *pBufferPtr, uint8_t ucSPIPacketLength)

{

 uint8_t ucCount;

    uint8_t ucDummyRead;

   

 /*Assert the CS Pin to Low for SPI Slave*/

    CS_LOW(GPIOB,GPIO_Pin_12);       

    Delayus(100);

 

 

   for (ucCount=0; ucCount < ucSPIPacketLength; ucCount++)

   {

  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) != SET);

  

  SPI_I2S_SendData(SPI2,*pBufferPtr );

  if(SPI2->DR != *pBufferPtr)

  {

   SPI_I2S_SendData(SPI2,*pBufferPtr );

  }

ucDummyRead =SPI_I2S_ReceiveData(SPI2);

  /*wait for transmission to complete */            

  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) != SET);

  Delayus(100);

  /*read the response from the spi rx buffer to dummy variable*/

  ucDummyRead =SPI_I2S_ReceiveData(SPI2);

 while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) ;     pBufferPtr++;     

   

    }

      CS_HIGH(GPIOB,GPIO_Pin_12);

    return SUCCESS;

   

}

#st
    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    March 5, 2013
    Posted on March 05, 2013 at 14:40

    Don't do this

     if(SPI2->DR != *pBufferPtr)

      {

       SPI_I2S_SendData(SPI2,*pBufferPtr );

      }

    Reading DR relects data in the RECEIVE buffer not the SEND buffer, stop doing this.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..