Other Parts Discussed in Thread: ADS1292
sir,I am using ads1292r with arduino for my project for acquisotion of ecg and respirartion signal.I was able to write the code seeing the ads1292r Datasheet.I am able to get the 72 bit data stream through spi,of which first 24 status bits say 192-0-0(8bit each) which translates to 1100 correctly according to datasheet.So I know I am getting real data through spi successfully .But my next 48 bit s i.e 24 bits of ecg and 24 bits of respiration
show a constant input voltage values irrespective of input.Attached is the header file,source file and main arduino file.please go through it and reply back soon.
ads1292r.h
#ifndef ads1292r_h
#define ads1292r_h
#include "Arduino.h"
// Register Read Commands
#define RREG 0x20; //Read n nnnn registers starting at address r rrrr
//first byte 001r rrrr (2xh)(2) - second byte 000n nnnn(2)
#define WREG 0x40; //Write n nnnn registers starting at address r rrrr
//first byte 010r rrrr (2xh)(2) - second byte 000n nnnn(2)
#define START 0x08 //Start/restart (synchronize) conversions
#define STOP 0x0A //Stop conversion
#define RDATAC 0x10 //Enable Read Data Continuous mode.
//This mode is the default mode at power-up.
#define SDATAC 0x11 //Stop Read Data Continuously mode
#define RDATA 0x12 //Read data by command; supports multiple read back.
//Pin declartion the other you need are controlled by the SPI library
const int ADS1292_DRDY_PIN = 6;
const int ADS1292_CS_PIN = 7;
const int ADS1292_START_PIN = 5;
const int ADS1292_PWDN_PIN = 4;
//register address
#define ADS1292_REG_ID 0x00
#define ADS1292_REG_CONFIG1 0x01
#define ADS1292_REG_CONFIG2 0x02
#define ADS1292_REG_LOFF 0x03
#define ADS1292_REG_CH1SET 0x04
#define ADS1292_REG_CH2SET 0x05
#define ADS1292_REG_RLDSENS 0x06
#define ADS1292_REG_LOFFSENS 0x07
#define ADS1292_REG_LOFFSTAT 0x08
#define ADS1292_REG_RESP1 0x09
#define ADS1292_REG_RESP2 0x0A
class ads1292r
{
public:
static void ads1292_Init(void);
static void ads1292_Reset(void);
static void ads1292_Reg_Write (unsigned char READ_WRITE_ADDRESS, unsigned char DATA);
static void ads1292_Reg_Read (unsigned char READ_WRITE_ADDRESS);
static void ads1292_SPI_Command_Data(unsigned char data_in);
static void ads1292_Disable_Start(void);
static void ads1292_Enable_Start(void);
static void ads1292_Hard_Stop (void);
static void ads1292_Start_Data_Conv_Command (void);
static void ads1292_Soft_Stop (void);
static void ads1292_Start_Read_Data_Continuous (void);
static void ads1292_Stop_Read_Data_Continuous (void);
static void read_ads(void);
};
#endif
ads1292r.c
#include <Arduino.h>
#include <ads1292r.h>
#include <SPI.h>
void ads1292r::ads1292_Init()
{
Serial.begin(57600);
// start the SPI library:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
//CPOL = 0, CPHA = 1
SPI.setDataMode(SPI_MODE1);
// Selecting 1Mhz clock for SPI
SPI.setClockDivider(SPI_CLOCK_DIV16);
ads1292_Reset();
delay(100);
ads1292_Disable_Start();
delay(100);
ads1292_Stop_Read_Data_Continuous(); // SDATAC command
delay(300);
ads1292_Reg_Write(ADS1292_REG_CONFIG1, 0x00); //Set sampling rate to 125 SPS
delay(10);
ads1292_Reg_Write(ADS1292_REG_CONFIG2, 0x80); //Lead-off comp off, test signal disabled
delay(10);
ads1292_Reg_Write(ADS1292_REG_LOFF, 0x10); //Lead-off defaults
delay(10);
ads1292_Reg_Write(ADS1292_REG_CH1SET, 0x00); //Ch 1 enabled, gain 6, connected to electrode in
delay(10);
ads1292_Reg_Write(ADS1292_REG_CH2SET, 0x00); //Ch 2 enabled, gain 6, connected to electrode in
delay(10);
ads1292_Reg_Write(ADS1292_REG_RLDSENS, 0b00101100); //RLD settings: fmod/16, RLD enabled, RLD inputs from Ch2 only
delay(10);
ads1292_Reg_Write(ADS1292_REG_LOFFSENS, 0x00); //LOFF settings: all disabled
delay(10);
//Skip register 8, LOFF Settings default
ads1292_Reg_Write(ADS1292_REG_RESP1, 0b11000010); //Respiration: MOD/DEMOD turned only, phase 0
delay(10);
ads1292_Reg_Write(ADS1292_REG_RESP2, 0b10000011); //Respiration: Calib OFF, respiration freq defaults
delay(10);
ads1292_Start_Data_Conv_Command();
delay(100);
ads1292_Start_Read_Data_Continuous();
delay(10);
}
void ads1292r::ads1292_Reset()
{
digitalWrite(ADS1292_PWDN_PIN, HIGH);
delay(100); // Wait 100 mSec
digitalWrite(ADS1292_PWDN_PIN, LOW);
delay(100);
digitalWrite(ADS1292_PWDN_PIN, HIGH);
delay(100);
}
void ads1292r::ads1292_Disable_Start()
{
digitalWrite(ADS1292_START_PIN, LOW);
delay(20);
}
void ads1292r::ads1292_Enable_Start()
{
digitalWrite(ADS1292_START_PIN, HIGH);
delay(20);
}
void ads1292r::ads1292_Hard_Stop (void)
{
digitalWrite(ADS1292_START_PIN, LOW);
delay(100);
}
void ads1292r::ads1292_Start_Data_Conv_Command (void)
{
ads1292_SPI_Command_Data(START); // Send 0x08 to the ADS1x9x
}
void ads1292r::ads1292_Soft_Stop (void)
{
ads1292_SPI_Command_Data(STOP); // Send 0x0A to the ADS1x9x
}
void ads1292r::ads1292_Start_Read_Data_Continuous (void)
{
ads1292_SPI_Command_Data(RDATAC); // Send 0x10 to the ADS1x9x
}
void ads1292r::ads1292_Stop_Read_Data_Continuous (void)
{
ads1292_SPI_Command_Data(SDATAC); // Send 0x11 to the ADS1x9x
}
void ads1292r::ads1292_SPI_Command_Data(unsigned char data_in)
{
byte data[1];
//data[0] = data_in;
digitalWrite(ADS1292_CS_PIN, LOW);
delay(2);
digitalWrite(ADS1292_CS_PIN, HIGH);
delay(2);
digitalWrite(ADS1292_CS_PIN, LOW);
delay(2);
SPI.transfer(data_in);
delay(2);
digitalWrite(ADS1292_CS_PIN, HIGH);
}
void ads1292r::ads1292_Reg_Write (unsigned char READ_WRITE_ADDRESS, unsigned char DATA)
{
switch (READ_WRITE_ADDRESS)
{
case 1:
DATA = DATA & 0x87;
break;
case 2:
DATA = DATA & 0xFB;
DATA |= 0x80;
break;
case 3:
DATA = DATA & 0xFD;
DATA |= 0x10;
break;
case 7:
DATA = DATA & 0x3F;
break;
case 8:
DATA = DATA & 0x5F;
break;
case 9:
DATA |= 0x02;
break;
case 10:
DATA = DATA & 0x87;
DATA |= 0x01;
break;
case 11:
DATA = DATA & 0x0F;
break;
default:
break;
}
// now combine the register address and the command into one byte:
byte dataToSend = READ_WRITE_ADDRESS | WREG;
digitalWrite(ADS1292_CS_PIN, LOW);
delay(2);
digitalWrite(ADS1292_CS_PIN, HIGH);
delay(2);
// take the chip select low to select the device:
digitalWrite(ADS1292_CS_PIN, LOW);
delay(2);
SPI.transfer(dataToSend); //Send register location
SPI.transfer(0x00); //number of register to wr
SPI.transfer(DATA); //Send value to record into register
delay(2);
// take the chip select high to de-select:
digitalWrite(ADS1292_CS_PIN, HIGH);
}
void ads1292r::read_ads(void)
{
uint32_t datax,datay;
int i;
digitalWrite(ADS1292_CS_PIN,LOW);
volatile int Data1 = SPI.transfer(0x00);
volatile int Data2 =SPI.transfer(0x00);
volatile int Data3 =SPI.transfer(0x00);
volatile int Data4 =SPI.transfer(0x00);
volatile int Data5 =SPI.transfer(0x00);
volatile int Data6 = SPI.transfer(0x00);
volatile int Data7 =SPI.transfer(0x00);
volatile int Data8 =SPI.transfer(0x00);
volatile int Data9 = SPI.transfer(0x00);
Serial.println(Data1,BIN);
datax=(Data4<<16) | (Data5<<8) | (Data6);
const int negative1 = (datax & (1 << 23)) != 0;
if (negative1)
datax = datax | ~((1 << 24) - 1);
double voltage1 = datax *(4.81/100000000) ;
//Serial.println(voltage1);
datay=(Data7<<16) | (Data8<<8) | (Data9);
const int negative2 = (datay & (1 << 24)) != 0;
if (negative2)
datay = datay | ~((1 << 24) - 1);
double voltage2 = datay *(4.81/100000000) ;
Serial.println(voltage2);
digitalWrite(ADS1292_CS_PIN,HIGH); //release chip, signal end transfer
return 0;
}
ecgsketch.ino
#include <ads1292r.h>
#include <SPI.h>
ads1292r ADS1292;
volatile unsigned int ECG=0;
void setup()
{
// initalize the data ready and chip select pins:
pinMode(ADS1292_DRDY_PIN, INPUT); //6
pinMode(ADS1292_CS_PIN, OUTPUT); //7
pinMode(ADS1292_START_PIN, OUTPUT); //5
pinMode(ADS1292_PWDN_PIN, OUTPUT); //4
//initalize ADS1292 slave
ADS1292.ads1292_Init();
}
void loop()
{
if((digitalRead(ADS1292_DRDY_PIN)) == LOW)
ADS1292.read_ads();
}