Hello,
I would like to ask you about the code for SPI interface with ADS1293. My goal is to acquire ECG data with ADS1293 and after that send them through SPI to Arduino Uno. However, the only thing I can see in serial plotter is a flat line. I just stuck on this. I would be grateful for your advice and opinions.
Thank you,
Daniel
#include <SPI.h>
/*
pin 6 = DRDYB (input)
pin 10 = CSB (output)
pin 11 = SDI/MOSI (output)
pin 12 = SDO/MISO (input)
pin 13 = SCLK (output)
*/
int mosi = 11;
int miso = 12;
int sclk = 13;
int dredy = 6;
int csb = 10;
const byte DATA_CH1_ECG_upper = 0x37;
const byte DATA_CH1_ECG_middle = 0x38;
const byte DATA_CH1_ECG_lower = 0x39;
void writeRegister(byte thisRegister, byte thisValue)
{
digitalWrite(csb, LOW);
SPI.transfer(thisRegister);
SPI.transfer(thisValue);
digitalWrite(csb, HIGH);
}
long readRegister(byte thisRegister)
{
long value;
digitalWrite(csb, LOW);
SPI.transfer(thisRegister^=128);
value = SPI.transfer(0x00);
digitalWrite(csb, HIGH);
return value;
}
void setup (void)
{
Serial.begin(9600);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV2);
pinMode (mosi, OUTPUT);
pinMode (miso, INPUT);
pinMode (sclk, OUTPUT);
pinMode (csb, OUTPUT);
pinMode (dredy, INPUT);
writeRegister(0x00,0x00); //Set address 0x00 = 0x01: Starts data conversion.
writeRegister(0x01,0x11); //Set address 0x01 = 0x11: Connect channel 1’s INP to IN2 and INN to IN1.
writeRegister(0x02,0x19); //Set address 0x02 = 0x19: Connect channel 2’s INP to IN3 and INN to IN1.
writeRegister(0x0A,0x07); //Set address 0x0A = 0x07: Enable the common-mode detector on input pins IN1, IN2 and IN3.
writeRegister(0x0C,0x04); //Set address 0x0C = 0x04: Connect the output of the RLD amplifier internally to pin IN4.
writeRegister(0x12,0x04); //Set address 0x12 = 0x04: Use external crystal and feed the internal oscillator's output to the digital.
writeRegister(0x14,0x24); //Set address 0x14 = 0x24: Shuts down unused channel 3’s signal path.
writeRegister(0x21,0x02); //Set address 0x21 = 0x02: Configures the R2 decimation rate as 5 for all channels.
writeRegister(0x22,0x02); //Set address 0x22 = 0x02: Configures the R3 decimation rate as 6 for channel 1.
writeRegister(0x23,0x02); //Set address 0x23 = 0x02: Configures the R3 decimation rate as 6 for channel 2.
writeRegister(0x27,0x08); //Set address 0x27 = 0x08: Configures the DRDYB source to channel 1 ECG (or fastest channel).
writeRegister(0x2F,0x30); //Set address 0x2F = 0x30: Enables channel 1 ECG and channel 2 ECG for loop read-back mode.
writeRegister(0x00,0x01); //Set address 0x00 = 0x01: Starts data conversion.
}
void loop (void)
{
if (digitalRead(dredy)== HIGH)
{
long ecg;
ecg = readRegister(DATA_CH2_ECG_upper) << 8;
ecg = ecg | readRegister(DATA_CH2_ECG_middle);
ecg = ecg << 8;
ecg = ecg | readRegister(DATA_CH2_ECG_lower);
Serial.println(ecg);
}
}