AnsweredAssumed Answered

STM32 SPI Problem receive only (with ADS1298)

Question asked by gleich.bernhard on Dec 30, 2012
Latest reply on Jul 14, 2014 by B.badreddine
Dear all,

I have just started working with STM32 microcontrollers (in this case it is a STM32F103VZE) coming from dsPIC controller family.
I want to port a ECG system using the ADS1298 (from TI) from dsPIC to STM32.
In order to configure the slave (ADS1298) proberly I use a easy SPI communication without DMA (later for ecg samples,
I will switch to Master mode receiving ony via DMA). Now I have a problem concerning SPI which is quite strange to me.

Transmission of commands works fine (checked with a logic analyzer), but receiving doesent work (allthough the ADS1298 device  sents the right commands back - checked with a logic analyzer) - see the two figures attached (one with decoding the sent command, the other decoding the answer of ADS1298).

Can anybody with more experience than me help? Thanks in advance


Here is the code snippet I used for transmission (it is quite the same as the STM example for SPI Flash and of one found in the ST forum)

--- main.c
uint8_t ReadValue[2] = {0xFF, 0xFF};
ReadValue[0] = SPISendByte(0x20);
ReadValue[1] = SPISendByte(0x00);

---- Here is the SPISENDBYTE function:

uint8_t SPISendByte(uint8_t byte)
    /** flush away any rogue data in rx buffer **/
    if (SPI_I2S_GetFlagStatus(SPI_ADS, SPI_I2S_FLAG_RXNE) == SET)
  /** Loop while DR register in not empty **/
    while(SPI_I2S_GetFlagStatus(SPI_ADS, SPI_I2S_FLAG_TXE) == RESET);

  /** Send byte through the SPI1 peripheral **/
  SPI_I2S_SendData(SPI_ADS, byte);

  /* Wait to receive a byte */
  while(SPI_I2S_GetFlagStatus(SPI_ADS, SPI_I2S_FLAG_RXNE) == RESET);

  /* Return the byte read from the SPI bus */
  return (uint8_t)SPI_I2S_ReceiveData(SPI_ADS);

-- Here is SPI configuration
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;        //2,25 MHz
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
    SPI_InitStructure.SPI_CRCPolynomial = 0;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    SPI_Init(SPI_ADS, &SPI_InitStructure);    //SPI1