cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 SPI Problem receive only (with ADS1298)

gleich
Associate II
Posted on December 30, 2012 at 16:16

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

Bernhard

------------------

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};

ADS1298Select;   

ReadValue[0] = SPISendByte(0x20);

ReadValue[1] = SPISendByte(0x00);

 Delay(1);

 ADS1298Deselect;

---- 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)

    {

        SPI_I2S_ReceiveData(SPI_ADS);

    }

  /** 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

5 REPLIES 5
jj2
Associate II
Posted on December 30, 2012 at 18:36

On my way to lunch (w/the boss) have to rush.

Are you aware that the SPI (received) data is clocked in at the same time as SPI (transmit) data is being sent?  (often via different clock edges)  One would expect that you first must ''condition/direct'' your SPI slave into some ''ready'' condition.  I would then suspect that you may have to transmit ''dummy'' data while your desired (receive) data now comes across. 

Such serial port issues (SPI and especially I2C) are always nasty when beginning.  Suggest that you find smallest/simplest part (perhaps SPI EEProm) and perfect your understanding with that - before doing battle w/more intense SPI Slave...

gleich
Associate II
Posted on December 31, 2012 at 09:42

Hey,

how was lunch with your boss?

I finally solved my problem. Indeed it was no problem. I only missed one delay in my power up sequencing of ADS slave. No it works, and I can go on to DMA ...

Greetings and happy new year

Bernhard

badreeddine2002
Associate
Posted on July 13, 2014 at 20:04

hey all,

please can you give the configuration of SPI and send/receive function for ads1298.

best regards

B.B

Posted on July 13, 2014 at 20:40

With two posts from 18 months ago this thread is rather old.

Suggest you state your specific system details, and that you review other SPI and display examples.

There have to be other SSD1289 SPI examples out there, for the STM32F103, and others.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
badreeddine2002
Associate
Posted on July 14, 2014 at 07:56

thank you for your help

it does work now. I was found the error

best regards