Arduino SPI with Texas instrument's ECG Analog Front End

Hi,

I am trying to interface arduino uno with Texas instrument's ECG Analog Front End ADS1293

DataSheet: http://www.ti.com/lit/ds/symlink/ads1293.pdf

/* this code is build to test the serial communication between the 
AFE ic and the arduino UNO 

the code build on 3/3/2015 at 1:19
the last modification was in :  10/3/2015 at 10:00

the used pin on this code are : 
1) pin 11 ; MOSI ; output
2) pin 12 ; MISO ; input
3) pin 13 ; SCK ; output 
4) pin 6 ; DRDYB ; input
5) pin 10; CSB ; output
*/

//include the library used for the SPI communcation
#include <SPI.h>


//define the used pin number on the arduino  
int mosi = 11;
int miso = 12;
int sck = 13;
int drdyb = 6;
int csb = 10;
char wordStr;
int counter = 0;
int VALUES = 100;
int DataReady; 


void setup() {
  Serial.begin(9600);
  SPI.begin();
  //the imprtant parmiter for SPI communication
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE2);// check the mode for the AFE 
  SPI.setClockDivider(SPI_CLOCK_DIV2);// this means 8MHz SCLK to the AFE  
  
  //set the pines mode as output/ input 
  pinMode (mosi, OUTPUT); //no need because it's not sending any data to the AFE
  pinMode (miso, INPUT);
  pinMode (sck, OUTPUT);
  pinMode (csb, OUTPUT);
  pinMode (drdyb, INPUT); 
}


void loop() {
  digitalWrite(csb, LOW);
  digitalWrite (mosi, HIGH);
  delay(0.32);
  digitalWrite(csb, HIGH);
  DataReady = digitalRead(drdyb);
  
  if ((DataReady = HIGH) & (counter < VALUES)){
    //this will make the serial communication start
    wordStr = digitalRead(miso);  // this is used for reading only or we need to save on variable 
    Serial.println(wordStr);
    counter = counter + 1;
  } 
  digitalWrite(csb, LOW);
}

I am not getting any output on the serial monitor of the arduino software..
Can you help me in debugging the code?

Thanks in advance
Hadeel

Let's start with this:

 if ((DataReady = HIGH) & (counter < VALUES)){

It should probably be this:

 if ((DataReady == HIGH) && (counter < VALUES)){

See if that makes any difference.

The other thing that might be a problem is that if the data ready is active LOW, then you should be looking for a LOW on the drdyb pin.
[edit] I've just read the PDF. It is active LOW, so you should use DataReady == LOW
It also might be worthwhile setting the drdyb pin as an input with pullup:

pinMode (drdyb, INPUT_PULLUP);

Pete

If you are using the SPI pins (10-13) as digital I/O pins you should probably NOT be using the SPI library. If you use the SPI library you should not be directly writing/reading MOSI, MISO, or SCLK.

  pinMode (mosi, OUTPUT); //no need because it's not sending any data to the AFE

If that is true why do you write to mosi at the top of loop?!?

el_supremo:
Let's start with this:

 if ((DataReady = HIGH) & (counter < VALUES)){

It should probably be this:

 if ((DataReady == HIGH) && (counter < VALUES)){

See if that makes any difference.

[/code]

Pete

Hi Supremo and thanks for the reply,

Actually when it is 'HIGH' I see something happening in the serial monitor (See the attached pic), while it doesn't happen when it is LOW.. Does this mean anything?

..

johnwasser:
If you are using the SPI pins (10-13) as digital I/O pins you should probably NOT be using the SPI library. If you use the SPI library you should not be directly writing/reading MOSI, MISO, or SCLK.

  pinMode (mosi, OUTPUT); //no need because it's not sending any data to the AFE

If that is true why do you write to mosi at the top of loop?!?

Hi John,

My setup is: ECG simulator connected to the Analog Front End using the serial 15pin port, then it is connected to the Arduino by the SPI pins and it SHOULD be sending and receiving data, so you can forget about that comment.........

PS. ECG Simulator is a device that simulate the Electrocardiogram of human body.

Thanks.

Does this mean anything?

Yes, it means that the device does not have any data ready but you are assuming that it does.
I've never used one of these devices so I can only go by what the datasheet says and that is that the DRDYB output is active low.
The datasheet has a lot of information about how to set up and read the data, including how to configure the DRDYB_SRC register. If you don't set that register, it will be zero and DRDYB will never be asserted (Figure 69 in the datasheet).

Pete