cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Sends Dummy bytes

pranathi1091
Associate II
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
1 REPLY 1
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
Up vote any posts that you find helpful, it shows what's working..