AnsweredAssumed Answered

SPI CS problem

Question asked by avi on Sep 12, 2014
Latest reply on Sep 29, 2014 by avi

Hi, everyone! 
I am working with communication between stm32F4 SPI2 to small A/D read only. The reading process is only one 16 bit word so I using SPI2 as a Master and my configuration looks like this:

  SPI_InitTypeDef  SPI_InitStructure; 

  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_RxOnly;

  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;

  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;//64;

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;


  SPI_Init(SPIx_APIT, &SPI_InitStructure);


When I processing read command I am using this :


uint16_t Get (void)


 uint16_t val1 = 0;  





 /*!< Wait to receive a byte */


while( !(SPI2->SR & SPI_I2S_FLAG_RXNE) ); // wait until receive complete


Val1 = SPI_I2S_ReceiveData(SPIx_APIT);  



return (uint16_t)(val1);


When ADCx_TRIG is an I/O that initiated sample from the A/D and the SPIx_APIT_CS config as a I/O.

This code is working good as you see in the first figure (yellow is clk, grin is CS and blue is trig for A/D)

Bat sometime (one in 300) the CS is up before time see the second figure and then I get fault data in my reading.


Is there anyone that can help me?