I want to interface ADS1298ECG-PDK with arduino can you please give me the sorce code for this.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I want to interface ADS1298ECG-PDK with arduino can you please give me the sorce code for this.
I found a arduino code from internet but not sure that weather it works well or not, kindly look at the code and suggest me.
/* * adsCMD.h * Library header file for adsCMD library */ #include "Arduino.h" //For Leonardo SPI see http://openenergymonitor.blogspot.com/2012/06/arduino-leonardo-atmega32u4-and-rfm12b.html //constants define pins on Arduino // Arduino Due const int IPIN_PWDN = 47; //not required for TI demo kit const int PIN_CLKSEL = 49;//6;//*optional const int IPIN_RESET = 48;//*optional const int PIN_START = 46; const int IPIN_DRDY = 45; const int IPIN_CS = 52; //const int PIN_DOUT = 11;//SPI out //const int PIN_DIN = 12;//SPI in //const int PIN_SCLK = 13;//SPI clock //function prototypes void adc_wreg(int reg, int val); //write register void adc_send_command(int cmd); //send command int adc_rreg(int reg); //read register /* adsCMD.cpp * simple library to light an LED for a duration given in milliseconds */ #include "Arduino.h" // use: Wprogram.h for Arduino versions prior to 1.0 #include "adsCMD.h" #include "ads1298.h" #include <SPI.h> // include the SPI library: void adc_send_command(int cmd) { digitalWrite(IPIN_CS, LOW); SPI.transfer(cmd); delayMicroseconds(1); digitalWrite(IPIN_CS, HIGH); } void adc_wreg(int reg, int val) { //see pages 40,43 of datasheet - digitalWrite(IPIN_CS, LOW); SPI.transfer(ADS1298::WREG | reg); SPI.transfer(0); // number of registers to be read/written � 1 SPI.transfer(val); delayMicroseconds(1); digitalWrite(IPIN_CS, HIGH); } int adc_rreg(int reg){ int out = 0; digitalWrite(IPIN_CS, LOW); SPI.transfer(ADS1298::RREG | reg); delayMicroseconds(5); SPI.transfer(0); // number of registers to be read/written � 1 delayMicroseconds(5); out = SPI.transfer(0); delayMicroseconds(1); #ifndef ADS1298_H #define ADS1298_H #ifdef __cplusplus namespace ADS1298 { #endif enum spi_command { // system commands WAKEUP = 0x02, STANDBY = 0x04, RESET = 0x06, START = 0x08, STOP = 0x0a, // read commands RDATAC = 0x10, SDATAC = 0x11, RDATA = 0x12, // register commands RREG = 0x20, WREG = 0x40 }; enum reg { // device settings ID = 0x00, // global settings CONFIG1 = 0x01, CONFIG2 = 0x02, CONFIG3 = 0x03, LOFF = 0x04, // channel specific settings CHnSET = 0x04, CH1SET = CHnSET + 1, CH2SET = CHnSET + 2, CH3SET = CHnSET + 3, CH4SET = CHnSET + 4, CH5SET = CHnSET + 5, CH6SET = CHnSET + 6, CH7SET = CHnSET + 7, CH8SET = CHnSET + 8, RLD_SENSP = 0x0d, RLD_SENSN = 0x0e, LOFF_SENSP = 0x0f, LOFF_SENSN = 0x10, LOFF_FLIP = 0x11, // lead off status LOFF_STATP = 0x12, LOFF_STATN = 0x13, // other GPIO = 0x14, PACE = 0x15, RESP = 0x16, CONFIG4 = 0x17, WCT1 = 0x18, WCT2 = 0x19 }; enum ID_bits { DEV_ID7 = 0x80, DEV_ID6 = 0x40, DEV_ID5 = 0x20, DEV_ID2 = 0x04, DEV_ID1 = 0x02, DEV_ID0 = 0x01, ID_const = 0x10, ID_ADS129x = DEV_ID7, ID_ADS129xR = (DEV_ID7 | DEV_ID6), ID_4CHAN = 0, ID_6CHAN = DEV_ID0, ID_8CHAN = DEV_ID1, ID_ADS1294 = (ID_ADS129x | ID_4CHAN), ID_ADS1296 = (ID_ADS129x | ID_6CHAN), ID_ADS1298 = (ID_ADS129x | ID_8CHAN), ID_ADS1294R = (ID_ADS129xR | ID_4CHAN), ID_ADS1296R = (ID_ADS129xR | ID_6CHAN), ID_ADS1298R = (ID_ADS129xR | ID_8CHAN) }; enum CONFIG1_bits { HR = 0x80, DAISY_EN = 0x40, CLK_EN = 0x20, DR2 = 0x04, DR1 = 0x02, DR0 = 0x01, CONFIG1_const = 0x00, HIGH_RES_32k_SPS = HR, HIGH_RES_16k_SPS = (HR | DR0), HIGH_RES_8k_SPS = (HR | DR1), HIGH_RES_4k_SPS = (HR | DR1 | DR0), HIGH_RES_2k_SPS = (HR | DR2), HIGH_RES_1k_SPS = (HR | DR2 | DR0), HIGH_RES_500_SPS = (HR | DR2 | DR1), LOW_POWR_250_SPS = (DR2 | DR1) }; enum CONFIG2_bits { WCT_CHOP = 0x20, INT_TEST = 0x10, TEST_AMP = 0x04, TEST_FREQ1 = 0x02, TEST_FREQ0 = 0x01, CONFIG2_const = 0x00, INT_TEST_4HZ = INT_TEST, INT_TEST_8HZ = (INT_TEST | TEST_FREQ0), INT_TEST_DC = (INT_TEST | TEST_FREQ1 | TEST_FREQ0) }; enum CONFIG3_bits { PD_REFBUF = 0x80, VREF_4V = 0x20, RLD_MEAS = 0x10, RLDREF_INT = 0x08, PD_RLD = 0x04, RLD_LOFF_SENS = 0x02, RLD_STAT = 0x01, CONFIG3_const = 0x40 }; enum LOFF_bits { COMP_TH2 = 0x80, COMP_TH1 = 0x40, COMP_TH0 = 0x20, VLEAD_OFF_EN = 0x10, ILEAD_OFF1 = 0x08, ILEAD_OFF0 = 0x04, FLEAD_OFF1 = 0x02, FLEAD_OFF0 = 0x01, LOFF_const = 0x00, COMP_TH_95 = 0x00, COMP_TH_92_5 = COMP_TH0, COMP_TH_90 = COMP_TH1, COMP_TH_87_5 = (COMP_TH1 | COMP_TH0), COMP_TH_85 = COMP_TH2, COMP_TH_80 = (COMP_TH2 | COMP_TH0), COMP_TH_75 = (COMP_TH2 | COMP_TH1), COMP_TH_70 = (COMP_TH2 | COMP_TH1 | COMP_TH0), ILEAD_OFF_6nA = 0x00, ILEAD_OFF_12nA = ILEAD_OFF0, ILEAD_OFF_18nA = ILEAD_OFF1, ILEAD_OFF_24nA = (ILEAD_OFF1 | ILEAD_OFF0), FLEAD_OFF_AC = FLEAD_OFF0, FLEAD_OFF_DC = (FLEAD_OFF1 | FLEAD_OFF0) }; enum CHnSET_bits { PDn = 0x80, PD_n = 0x80, GAINn2 = 0x40, GAINn1 = 0x20, GAINn0 = 0x10, MUXn2 = 0x04, MUXn1 = 0x02, MUXn0 = 0x01, CHnSET_const = 0x00, GAIN_1X = GAINn0, GAIN_2X = GAINn1, GAIN_3X = (GAINn1 | GAINn0), GAIN_4X = GAINn2, GAIN_6X = 0x00, GAIN_8X = (GAINn2 | GAINn0), GAIN_12X = (GAINn2 | GAINn1), ELECTRODE_INPUT = 0x00, SHORTED = MUXn0, RLD_INPUT = MUXn1, MVDD = (MUXn1 | MUXn0), TEMP = MUXn2, TEST_SIGNAL = (MUXn2 | MUXn0), RLD_DRP = (MUXn2 | MUXn1), RLD_DRN = (MUXn2 | MUXn1 | MUXn0) }; enum CH1SET_bits { PD_1 = 0x80, GAIN12 = 0x40, GAIN11 = 0x20, GAIN10 = 0x10, MUX12 = 0x04, MUX11 = 0x02, MUX10 = 0x01, CH1SET_const = 0x00 }; enum CH2SET_bits { PD_2 = 0x80, GAIN22 = 0x40, GAIN21 = 0x20, GAIN20 = 0x10, MUX22 = 0x04, MUX21 = 0x02, MUX20 = 0x01, CH2SET_const = 0x00 }; enum CH3SET_bits { PD_3 = 0x80, GAIN32 = 0x40, GAIN31 = 0x20, GAIN30 = 0x10, MUX32 = 0x04, MUX31 = 0x02, MUX30 = 0x01, CH3SET_const = 0x00 }; enum CH4SET_bits { PD_4 = 0x80, GAIN42 = 0x40, GAIN41 = 0x20, GAIN40 = 0x10, MUX42 = 0x04, MUX41 = 0x02, MUX40 = 0x01, CH4SET_const = 0x00 }; enum CH5SET_bits { PD_5 = 0x80, GAIN52 = 0x40, GAIN51 = 0x20, GAIN50 = 0x10, MUX52 = 0x04, MUX51 = 0x02, MUX50 = 0x01, CH5SET_const = 0x00 }; enum CH6SET_bits { PD_6 = 0x80, GAIN62 = 0x40, GAIN61 = 0x20, GAIN60 = 0x10, MUX62 = 0x04, MUX61 = 0x02, MUX60 = 0x01, CH6SET_const = 0x00 }; enum CH7SET_bits { PD_7 = 0x80, GAIN72 = 0x40, GAIN71 = 0x20, GAIN70 = 0x10, MUX72 = 0x04, MUX71 = 0x02, MUX70 = 0x01, CH7SET_const = 0x00 }; enum CH8SET_bits { PD_8 = 0x80, GAIN82 = 0x40, GAIN81 = 0x20, GAIN80 = 0x10, MUX82 = 0x04, MUX81 = 0x02, MUX80 = 0x01, CH8SET_const = 0x00 }; enum RLD_SENSP_bits { RLD8P = 0x80, RLD7P = 0x40, RLD6P = 0x20, RLD5P = 0x10, RLD4P = 0x08, RLD3P = 0x04, RLD2P = 0x02, RLD1P = 0x01, RLD_SENSP_const = 0x00 }; enum RLD_SENSN_bits { RLD8N = 0x80, RLD7N = 0x40, RLD6N = 0x20, RLD5N = 0x10, RLD4N = 0x08, RLD3N = 0x04, RLD2N = 0x02, RLD1N = 0x01, RLD_SENSN_const = 0x00 }; enum LOFF_SENSP_bits { LOFF8P = 0x80, LOFF7P = 0x40, LOFF6P = 0x20, LOFF5P = 0x10, LOFF4P = 0x08, LOFF3P = 0x04, LOFF2P = 0x02, LOFF1P = 0x01, LOFF_SENSP_const = 0x00 }; enum LOFF_SENSN_bits { LOFF8N = 0x80, LOFF7N = 0x40, LOFF6N = 0x20, LOFF5N = 0x10, LOFF4N = 0x08, LOFF3N = 0x04, LOFF2N = 0x02, LOFF1N = 0x01, LOFF_SENSN_const = 0x00 }; enum LOFF_FLIP_bits { LOFF_FLIP8 = 0x80, LOFF_FLIP7 = 0x40, LOFF_FLIP6 = 0x20, LOFF_FLIP5 = 0x10, LOFF_FLIP4 = 0x08, LOFF_FLIP3 = 0x04, LOFF_FLIP2 = 0x02, LOFF_FLIP1 = 0x01, LOFF_FLIP_const = 0x00 }; enum LOFF_STATP_bits { IN8P_OFF = 0x80, IN7P_OFF = 0x40, IN6P_OFF = 0x20, IN5P_OFF = 0x10, IN4P_OFF = 0x08, IN3P_OFF = 0x04, IN2P_OFF = 0x02, IN1P_OFF = 0x01, LOFF_STATP_const = 0x00 }; enum LOFF_STATN_bits { IN8N_OFF = 0x80, IN7N_OFF = 0x40, IN6N_OFF = 0x20, IN5N_OFF = 0x10, IN4N_OFF = 0x08, IN3N_OFF = 0x04, IN2N_OFF = 0x02, IN1N_OFF = 0x01, LOFF_STATN_const = 0x00 }; enum GPIO_bits { GPIOD4 = 0x80, GPIOD3 = 0x40, GPIOD2 = 0x20, GPIOD1 = 0x10, GPIOC4 = 0x08, GPIOC3 = 0x04, GPIOC2 = 0x02, GPIOC1 = 0x01, GPIO_const = 0x00 }; enum PACE_bits { PACEE1 = 0x10, PACEE0 = 0x08, PACEO1 = 0x04, PACEO0 = 0x02, PD_PACE = 0x01, PACE_const = 0x00, PACEE_CHAN2 = 0x00, PACEE_CHAN4 = PACEE0, PACEE_CHAN6 = PACEE1, PACEE_CHAN8 = (PACEE1 | PACEE0), PACEO_CHAN1 = 0x00, PACEO_CHAN3 = PACEE0, PACEO_CHAN5 = PACEE1, PACEO_CHAN7 = (PACEE1 | PACEE0) }; enum RESP_bits { RESP_DEMOD_EN1 = 0x80, RESP_MOD_EN1 = 0x40, RESP_PH2 = 0x10, RESP_PH1 = 0x08, RESP_PH0 = 0x04, RESP_CTRL1 = 0x02, RESP_CTRL0 = 0x01, RESP_const = 0x20, RESP_PH_22_5 = 0x00, RESP_PH_45 = RESP_PH0, RESP_PH_67_5 = RESP_PH1, RESP_PH_90 = (RESP_PH1 | RESP_PH0), RESP_PH_112_5 = RESP_PH2, RESP_PH_135 = (RESP_PH2 | RESP_PH0), RESP_PH_157_5 = (RESP_PH2 | RESP_PH1), RESP_NONE = 0x00, RESP_EXT = RESP_CTRL0, RESP_INT_SIG_INT = RESP_CTRL1, RESP_INT_SIG_EXT = (RESP_CTRL1 | RESP_CTRL0) }; enum CONFIG4_bits { RESP_FREQ2 = 0x80, RESP_FREQ1 = 0x40, RESP_FREQ0 = 0x20, SINGLE_SHOT = 0x08, WCT_TO_RLD = 0x04, PD_LOFF_COMP = 0x02, CONFIG4_const = 0x00, RESP_FREQ_64k_Hz = 0x00, RESP_FREQ_32k_Hz = RESP_FREQ0, RESP_FREQ_16k_Hz = RESP_FREQ1, RESP_FREQ_8k_Hz = (RESP_FREQ1 | RESP_FREQ0), RESP_FREQ_4k_Hz = RESP_FREQ2, RESP_FREQ_2k_Hz = (RESP_FREQ2 | RESP_FREQ0), RESP_FREQ_1k_Hz = (RESP_FREQ2 | RESP_FREQ1), RESP_FREQ_500_Hz = (RESP_FREQ2 | RESP_FREQ1 | RESP_FREQ0) }; enum WCT1_bits { aVF_CH6 = 0x80, aVL_CH5 = 0x40, aVR_CH7 = 0x20, avR_CH4 = 0x10, PD_WCTA = 0x08, WCTA2 = 0x04, WCTA1 = 0x02, WCTA0 = 0x01, WCT1_const = 0x00, WCTA_CH1P = 0x00, WCTA_CH1N = WCTA0, WCTA_CH2P = WCTA1, WCTA_CH2N = (WCTA1 | WCTA0), WCTA_CH3P = WCTA2, WCTA_CH3N = (WCTA2 | WCTA0), WCTA_CH4P = (WCTA2 | WCTA1), WCTA_CH4N = (WCTA2 | WCTA1 | WCTA0) }; enum WCT2_bits { PD_WCTC = 0x80, PD_WCTB = 0x40, WCTB2 = 0x20, WCTB1 = 0x10, WCTB0 = 0x08, WCTC2 = 0x04, WCTC1 = 0x02, WCTC0 = 0x01, WCT2_const = 0x00, WCTB_CH1P = 0x00, WCTB_CH1N = WCTB0, WCTB_CH2P = WCTB1, WCTB_CH2N = (WCTB1 | WCTB0), WCTB_CH3P = WCTB2, WCTB_CH3N = (WCTB2 | WCTB0), WCTB_CH4P = (WCTB2 | WCTB1), WCTB_CH4N = (WCTB2 | WCTB1 | WCTB0), WCTC_CH1P = 0x00, WCTC_CH1N = WCTC0, WCTC_CH2P = WCTC1, WCTC_CH2N = (WCTC1 | WCTC0), WCTC_CH3P = WCTC2, WCTC_CH3N = (WCTC2 | WCTC0), WCTC_CH4P = (WCTC2 | WCTC1), WCTC_CH4N = (WCTC2 | WCTC1 | WCTC0) }; #ifdef __cplusplus } #endif /* namespace ADS1298 */ #endif /* ADS1298_H */ // Minimal sketch for connection to ADS129n family. Load this script and open Tools/SerialMonitor. // You should see text like this // Device Type (ID Control Register): 62 Channels: 8 // If you see "Channels: 0" then check your wiring #include "ads1298.h" #include "adsCMD.h" #include <SPI.h> // include the SPI library: int gMaxChan = 0; //maximum number of channels supported by ads129n = 4,6,8 int gIDval = 0; //Device ID : lower 5 bits of ID Control Register int activeSerialPort = 0; //data will be sent to serial port that last sent commands. E.G. bluetooth or USB port const int kPIN_LED = 13;//pin with in-built light - typically 13, 11 for Teensy 2.0. #if defined(__SAM3X8E__) #define isDUE //Detect Arduino Due //#define WiredSerial SerialUSB //Use Due's Native port #define WiredSerial Serial #else #define WiredSerial Serial #endif void setup(){ using namespace ADS1298; //prepare pins to be outputs or inputs //pinMode(PIN_SCLK, OUTPUT); //optional - SPI library will do this for us //pinMode(PIN_DIN, OUTPUT); //optional - SPI library will do this for us //pinMode(PIN_DOUT, INPUT); //optional - SPI library will do this for us pinMode(IPIN_CS, OUTPUT); pinMode(PIN_START, OUTPUT); pinMode(IPIN_DRDY, INPUT); pinMode(PIN_CLKSEL, OUTPUT);//*optional pinMode(IPIN_RESET, OUTPUT);//*optional pinMode(IPIN_PWDN, OUTPUT);//*optional //start Serial Peripheral Interface SPI.begin(); SPI.setBitOrder(MSBFIRST); #ifndef isDUE SPI.setClockDivider(SPI_CLOCK_DIV4); //http://forum.pjrc.com/threads/1156-Teensy-3-SPI-Basic-Clock-Questions #endif SPI.setDataMode(SPI_MODE1); //Start ADS1298 delay(500); //wait for the ads129n to be ready - it can take a while to charge caps adc_send_command(SDATAC); // Send SDATAC Command (Stop Read Data Continuously mode) delay(10); // Determine model number and number of channels available gIDval = adc_rreg(ID); //lower 5 bits of register 0 reveal chip type switch (gIDval & B00011111 ) { //least significant bits reports channels case B10000: //16 gMaxChan = 4; //ads1294 break; case B10001: //17 gMaxChan = 6; //ads1296 break; case B10010: //18 gMaxChan = 8; //ads1298 break; case B11110: //30 gMaxChan = 8; //ads1299 break; default: gMaxChan = 0; } //start serial port WiredSerial.begin(115200); //use native port on Due while (WiredSerial.read() >= 0) {} //http://forum.arduino.cc/index.php?topic=134847.0 //while (!WiredSerial) ; //required by Leonardo http://arduino.cc/en/Serial/IfSerial (ads129n requires 3.3v signals, Leonardo is 5v) delay(200); // Catch Due reset problem pinMode(kPIN_LED, OUTPUT); } void loop() { WiredSerial.print("Device Type (ID Control Register): "); WiredSerial.print(gIDval); WiredSerial.print(" Channels: "); WiredSerial.println(gMaxChan); digitalWrite(kPIN_LED, HIGH); // turn the LED on (HIGH is the voltage level) if (gMaxChan > 0) delay(500); //long pause if OK else delay(50); //rapid blink if error digitalWrite(kPIN_LED, LOW); // turn the LED off by making the voltage LOW delay(500); } digitalWrite(IPIN_CS, HIGH); return(out); }