Hello all,
I am using an Arduino Uno to communicate through SPI with the ADS1298. I am able to write to registers and change the pulse timing of DRDY, but now I want to input a signal through one of the channels. If I want to use an external function generator to connect to channel 1, what must I change in the code for this to work? And are there any other connections that need to be made?
I was trying to follow the datasheet and tried multiple configurations of the code but no luck. Output of DOUT is stuck at 11000000000000000000000 (only 23 bits). I am assuming I must change the Channel 1 Setting but am unsure of what value, and also unsure what to leave channels 2-8 to be set as. Also confused on Config 2 setting for this setup.
Any suggestions?
#include <SPI.h> #include <SD.h> #define MISOPIN 12 const int CS = 10; const int START = 4; const int DRDY = 6; const int RESET = 2; const int CLKSEL = 5; const int PWDN = 3; void setup() { pinMode(RESET, OUTPUT); pinMode(CS, OUTPUT); pinMode(START, OUTPUT); pinMode(DRDY, INPUT); //init SPI bus, SCK, MOSI & SS to outputs. pull SCK and MOSI low, SS high SPI.begin(); Serial.begin(9600); //shifts data with MSB first SPI.setBitOrder(MSBFIRST); delay(500); delay(100); digitalWrite(CLKSEL,HIGH); delay(1000); //Power on reset digitalWrite(PWDN,HIGH); digitalWrite(RESET,HIGH); delay(1000); digitalWrite(RESET,LOW); delay(1000); digitalWrite(RESET,HIGH); delay(1000); //OPCODE: stop read data continuously adc_send_command(0x11); //Register write values adsSetup(); digitalWrite(START, HIGH); delay(100); //RDATAC opcode adc_send_command(0x10); drdy_delay(); } //Defining Struct function struct{ operator uint32_t() const { return (uint32_t( SPI.transfer(0x00) ) << 16) + (SPI.transfer(0x00) << 8) + SPI.transfer(0x00); } } ADC_24Bit; byte byte1; byte byte2; byte byte3; void adsSetup() { adc_wreg(0x03, 0xC0); //Write 0xC0 to CONFIG3 (0x03) as required in the flowchart adc_wreg(0x01, 0x86); //Write 0x86 to CONFIG1 (0x01) as required in the flowchart adc_wreg(0x02, 0x20); //Write 0x00 to CONFIG2 (0x02) as required in the flowchart adc_wreg(0x05, 0x00); //CHnSET (0x05 - 0x0C must be shorted with 0x01) adc_wreg(0x06, 0x01); adc_wreg(0x07, 0x01); adc_wreg(0x08, 0x01); adc_wreg(0x09, 0x01); adc_wreg(0x0A, 0x01); adc_wreg(0x0B, 0x01); adc_wreg(0x0C, 0x01); } void adc_send_command(int cmd) { digitalWrite(RESET, HIGH); digitalWrite(CS, LOW); SPI.transfer(cmd); delayMicroseconds(3); digitalWrite(CS, HIGH); } void adc_wreg(int reg, int val) { digitalWrite(RESET, HIGH); digitalWrite(CS, LOW); SPI.transfer(0x40 | reg); SPI.transfer(0x0A); SPI.transfer(val); delayMicroseconds(1); digitalWrite(CS, HIGH); } void read_adc() { digitalWrite(CS, LOW); Serial.println( ADC_24Bit, BIN ); } void drdy_delay() { if (DRDY == 0) { delayMicroseconds(3); } } void loop () { if(digitalRead(DRDY) == 0 ) { read_adc(); } delay(10); }