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;  

 ADCx_TRIG_LOW();

 ADCx_TRIG_HIGH();

 DelayPit(20);

 SPIx_APIT_CS_LOW();

 /*!< Wait to receive a byte */

 SPI_Cmd(SPIx_APIT, ENABLE);

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

SPIx_APIT_CS_HIGH();

Val1 = SPI_I2S_ReceiveData(SPIx_APIT);  

SPI_Cmd(SPIx_APIT, DISABLE);

DelayPit(1);

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.

spi1_thumb.jpg
spi2.jpg

Is there anyone that can help me?


Outcomes