possibly working ads1298 biopotential mesurement chip maple code.
The ads1298 biopotential mesurement chip samples at 16ksps to take all the information in possible from mucle signals.
To do this after the analog mesurements are fully tested the data out will be connected to the usb1232h module made by dlp that has a high speed usb FT2232h chip.
but here is the code for my open source project I will check if the GPIO status changes in the firs output 24 bit word.
next I will use my mp3 player and audacity & the headphone wires going to the board to try to have it mesure a sign wave.
code main loop and setup function code.
<br /> //set pin names<br /> int ledPin = 13; // LED connected to digital pin 13 d13<br /> int RESET = 11; //reset pin active reset low d11.<br /> int START = 10; //start pin activate conversion when high d11.<br /> int DRDY = 12; //active low when data is ready to be read d12.<br /> int cs_main = 9; //selects main chip to configure registers d9<br /> int cs_secondary =8; //selects non-main chip to configure registers d8<br /> int sclk=14; //system clock for all the other pins d14<br /> int doutMISO_0=0; //doutMISO of the main chip 1-7 secondary chips master in slave out<br /> int dinMOSI_0=15; //data in to main pin Master out slave in</p> <p>//global vareables<br /> int buttonState=LOW;<br /> int drdy_State=HIGH;<br /> int dout_input=LOW;<br /> int reg_number=0;<br /> int register_val=0;<br /> int reg_data=0;<br /> int sample_1=0;<br /> int sample_2=0;<br /> int sample_3=0;<br /> int sample_4=0;<br /> int sample_5=0;<br /> int sample_6=0;<br /> int sample_7=0;<br /> int sample_8=0;<br /> int status_0=0;</p> <p>// The setup() method runs once, when the sketch starts</p> <p>void setup() { </p> <p> SerialUSB.println("Hello World!"); //delay setup configure print</p> <p> ads1298_Setup();</p> <p> //Setup Registers<br /> setup_registers();</p> <p> delay(1000); //wait 1 s</p> <p> digitalWrite(START, HIGH);</p> <p> //check for drdy change before reading registers...<br /> while(drdy_State==HIGH){<br /> drdy_State = digitalRead(DRDY);<br /> if(drdy_State==LOW){ </p> <p> read_n_print_9_words();</p> <p> digitalWrite(ledPin, HIGH);<br /> }<br /> }</p> <p>}<br /> // the loop() method runs over and over again,<br /> // as long as the Maple has power</p> <p>void loop()<br /> {<br /> drdy_State = digitalRead(DRDY);<br /> if(drdy_State==LOW){ </p> <p> //show the status of the gpio register over and over..</p> <p> read_9_words_print_status();</p> <p> }</p> <p>}</p> <p>
file 2: function definitions
//set pin names
extern int ledPin; // LED connected to digital pin 13 d13
extern int RESET; //reset pin active reset low d10.
extern int START; //start pin activate conversion when high d11.
extern int DRDY; //active low when data is ready to be read d12.
extern int cs_main; //selects main chip to configure registers d9
extern int cs_secondary; //selects non-main chip to configure registers d9
extern int sclk; //system clock for all the other pins d14
extern int doutMISO_0; //doutMISO of the main chip 2-7 secondary chips master in slave out
extern int dinMOSI_0; //data in to all other pins Master out slave in//global vareables
extern int buttonState;
extern int drdy_State;
extern int dout_input;
extern int reg_number;
extern int register_val;
extern int reg_data;
extern int sample_1;
extern int sample_2;
extern int sample_3;
extern int sample_4;
extern int sample_5;
extern int sample_6;
extern int sample_7;
extern int sample_8;
extern int status_0;void ads1298_Setup(void){
SerialUSB.println("ADS1298 power up!");
//setup pins for inputs and outputs
pinMode(ledPin, OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(START, OUTPUT);
pinMode(DRDY, INPUT);
pinMode(cs_main, OUTPUT);
pinMode(cs_secondary, OUTPUT);
pinMode(sclk, OUTPUT);
pinMode(doutMISO_0, INPUT);
pinMode(dinMOSI_0, OUTPUT);
//tie all low
digitalWrite(START, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(cs_main, LOW);
digitalWrite(cs_secondary, LOW);
digitalWrite(sclk, LOW);
digitalWrite(dinMOSI_0, LOW);ads1298_Power_Up();
send_Reset_Command();
//send command Stop Read Data Continuously mode
sdatac();//comand sent to read = RREG When in RDATAC mode, the RREG command is ignored.
}
void ads1298_Power_Up(void){
//step 1 wait 500ms instead of recomended 150ms
//for power supplies to stableise
delay(500);
//set CLKSEL=1 wait 20us //allready set to 1 unless tie to pin.
delay(500); //wait 500ms instead of 20us to let clk stableise
//wait 2^16 tclk = 65536 tclk 2.x Mhz
delay(1000); //wait 1 s instead of 65536 tclk
//reset pulse low wait 18tclks longer low wait 5 sec for power on reset
//reset allready tied HIGH
digitalWrite(RESET, LOW);
delay(100);
digitalWrite(RESET, HIGH);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
}void sclk_toggle_dinMOSI_0_L(void){
digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, LOW);
digitalWrite(sclk, LOW);}
void sclk_toggle_dinMOSI_0_H(void){
digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, HIGH);
digitalWrite(sclk, LOW);}
void send_Reset_Command(void){
//0000 0110
//msb first
//set configuration registers...
sclk_toggle_dinMOSI_0_L();//b7 = 0
sclk_toggle_dinMOSI_0_L();//b6 = 0
sclk_toggle_dinMOSI_0_L();//b5 = 0
sclk_toggle_dinMOSI_0_L();//b4 = 0sclk_toggle_dinMOSI_0_L();//b3 = 0
sclk_toggle_dinMOSI_0_H();//b2 = 1
sclk_toggle_dinMOSI_0_H();//b1 = 1
sclk_toggle_dinMOSI_0_L();//b0 = 0
//delay after reset
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);}
void sdatac(void){
//SDATAC
//0001 0001
sclk_toggle_dinMOSI_0_L();//b7 = 0
sclk_toggle_dinMOSI_0_L();//b6 = 0
sclk_toggle_dinMOSI_0_L();//b5 = 0
sclk_toggle_dinMOSI_0_H();//b4 = 1sclk_toggle_dinMOSI_0_L();//b3 = 0
sclk_toggle_dinMOSI_0_L();//b2 = 0
sclk_toggle_dinMOSI_0_L();//b1 = 0
sclk_toggle_dinMOSI_0_H();//b0 = 1}
void rreg (void){
//001
sclk_toggle_dinMOSI_0_L();//b7 = 0
sclk_toggle_dinMOSI_0_L();//b6 = 0
sclk_toggle_dinMOSI_0_H();//b5 = 1}
void rw_byte_1(void){
//number of bytes value 0 = read 1 byte
sclk_toggle_dinMOSI_0_L();//b7 = 0
sclk_toggle_dinMOSI_0_L();//b6 = 0
sclk_toggle_dinMOSI_0_L();//b5 = 0
sclk_toggle_dinMOSI_0_L();//b4 = 0sclk_toggle_dinMOSI_0_L();//b3 = 0
sclk_toggle_dinMOSI_0_L();//b2 = 0
sclk_toggle_dinMOSI_0_L();//b1 = 0
sclk_toggle_dinMOSI_0_L();//b0 = 0}
void toggle_sclk(void){
digitalWrite(sclk, HIGH);
digitalWrite(sclk, LOW);}
void wreg(void){
//010
sclk_toggle_dinMOSI_0_L();//b7 = 0
sclk_toggle_dinMOSI_0_H();//b6 = 1
sclk_toggle_dinMOSI_0_L();//b5 = 0}
void write_reg(int reg_number, int in){
wreg();
digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,4));//b4
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,3));//b3
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,2));//b2
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,1));//b1
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,0));//b0
digitalWrite(sclk, LOW);rw_byte_1();
write_byte_to_reg(in);
}void write_byte_to_reg(int reg_data){
digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,7));//b7
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,6));//b6
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,5));//b5
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,4));//b4
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,3));//b3
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,2));//b2
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,1));//b1
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_data,0));//b0
digitalWrite(sclk, LOW);}
int sclk_out_byte_ret(void){
int out;
toggle_sclk();//b7
dout_input = digitalRead(doutMISO_0);
bitWrite(out,7,dout_input);toggle_sclk();//b6
dout_input = digitalRead(doutMISO_0);
bitWrite(out,6,dout_input);toggle_sclk();//b5
dout_input = digitalRead(doutMISO_0);
bitWrite(out,5,dout_input);toggle_sclk();//b4
dout_input = digitalRead(doutMISO_0);
bitWrite(out,4,dout_input);toggle_sclk();//b3
dout_input = digitalRead(doutMISO_0);
bitWrite(out,3,dout_input);toggle_sclk();//b2
dout_input = digitalRead(doutMISO_0);
bitWrite(out,2,dout_input);toggle_sclk();//b1
dout_input = digitalRead(doutMISO_0);
bitWrite(out,1,dout_input);toggle_sclk();//b0
dout_input = digitalRead(doutMISO_0);
bitWrite(out,0,dout_input);return(out);
}int read_reg_ret(int reg_number){
int out = 0;
rreg();
digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,4));//b4
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,3));//b3
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,2));//b2
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,1));//b1
digitalWrite(sclk, LOW);digitalWrite(sclk, HIGH);
digitalWrite(dinMOSI_0, bitRead(reg_number,0));//b0
digitalWrite(sclk, LOW);rw_byte_1();
out = sclk_out_byte_ret();
return(out);
}void rdatac(void){
//RDATAC
//0001 0000 (10h)
sclk_toggle_dinMOSI_0_L();//b7 = 0
sclk_toggle_dinMOSI_0_L();//b6 = 0
sclk_toggle_dinMOSI_0_L();//b5 = 0
sclk_toggle_dinMOSI_0_H();//b4 = 1sclk_toggle_dinMOSI_0_L();//b3 = 0
sclk_toggle_dinMOSI_0_L();//b2 = 0
sclk_toggle_dinMOSI_0_L();//b1 = 0
sclk_toggle_dinMOSI_0_L();//b0 = 0}
int sclk_out_word_ret24(void){
int out;toggle_sclk();//b23
dout_input = digitalRead(doutMISO_0);
bitWrite(out,23,dout_input);
toggle_sclk();//b22
dout_input = digitalRead(doutMISO_0);
bitWrite(out,22,dout_input);
toggle_sclk();//b21
dout_input = digitalRead(doutMISO_0);
bitWrite(out,21,dout_input);
toggle_sclk();//b20
dout_input = digitalRead(doutMISO_0);
bitWrite(out,20,dout_input);
toggle_sclk();//b19
dout_input = digitalRead(doutMISO_0);
bitWrite(out,19,dout_input);
toggle_sclk();//b18
dout_input = digitalRead(doutMISO_0);
bitWrite(out,18,dout_input);
toggle_sclk();//b17
dout_input = digitalRead(doutMISO_0);
bitWrite(out,17,dout_input);
toggle_sclk();//b16
dout_input = digitalRead(doutMISO_0);
bitWrite(out,16,dout_input);toggle_sclk();//b15
dout_input = digitalRead(doutMISO_0);
bitWrite(out,15,dout_input);
toggle_sclk();//b14
dout_input = digitalRead(doutMISO_0);
bitWrite(out,14,dout_input);
toggle_sclk();//b13
dout_input = digitalRead(doutMISO_0);
bitWrite(out,13,dout_input);
toggle_sclk();//b12
dout_input = digitalRead(doutMISO_0);
bitWrite(out,12,dout_input);
toggle_sclk();//b11
dout_input = digitalRead(doutMISO_0);
bitWrite(out,11,dout_input);
toggle_sclk();//b10
dout_input = digitalRead(doutMISO_0);
bitWrite(out,10,dout_input);
toggle_sclk();//b9
dout_input = digitalRead(doutMISO_0);
bitWrite(out,9,dout_input);
toggle_sclk();//b8
dout_input = digitalRead(doutMISO_0);
bitWrite(out,8,dout_input);toggle_sclk();//b7
dout_input = digitalRead(doutMISO_0);
bitWrite(out,7,dout_input);
toggle_sclk();//b6
dout_input = digitalRead(doutMISO_0);
bitWrite(out,6,dout_input);
toggle_sclk();//b5
dout_input = digitalRead(doutMISO_0);
bitWrite(out,5,dout_input);
toggle_sclk();//b4
dout_input = digitalRead(doutMISO_0);
bitWrite(out,4,dout_input);
toggle_sclk();//b3
dout_input = digitalRead(doutMISO_0);
bitWrite(out,3,dout_input);
toggle_sclk();//b2
dout_input = digitalRead(doutMISO_0);
bitWrite(out,2,dout_input);
toggle_sclk();//b1
dout_input = digitalRead(doutMISO_0);
bitWrite(out,1,dout_input);
toggle_sclk();//b0
dout_input = digitalRead(doutMISO_0);
bitWrite(out,0,dout_input);return(out);
}void setup_registers(void){
//READ DEVICE SETTINGS ****************
//read register 0
register_val=read_reg_ret(0);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 0 Shows 010 at the end 8 channel & ID");//SET GLOBAL SETTINGS ACROSS CHANNELS *****************
//write register address 1 config1
//value 10100001=161=high res,daisy chain,osc out,16ksps
write_reg(1, 161);
//read register 1
register_val=read_reg_ret(1);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 1 Shows value 10100001=161=high res,daisy chain,osc out,16ksps");//write register address 2 config2
//value 0000 0000=0=fclk /1
write_reg(2, 0);
register_val=read_reg_ret(2);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 2 Shows fclk /1");//write register address 3 config3
//value b1100 0100=196=7=en ref buf 2=rld buf en RLD Buffer bit 2
write_reg(3, 196);
register_val=read_reg_ret(3);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 3 en ref buf 2=rld buf en RLD Buffer bit 2");//write register address 4 LOFF
//value b0000 0000=0=00 = 00 = Lead-off detection turned off (default)
write_reg(4, 0);
register_val=read_reg_ret(4);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 4 Shows 00 = Lead-off detection turned off (default)");//CHANNEL SPECIFIC SETTINGS
//these will be very similar
//write register address 5-12 CH1-8SET
//value b0001 0000=16=6:4=001 gain =1
write_reg(5, 16);
write_reg(6, 16);
write_reg(7, 16);
write_reg(8, 16);
write_reg(9, 16);
write_reg(10, 16);
write_reg(11, 16);
write_reg(12, 16);register_val=read_reg_ret(5);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(6);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(7);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(8);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(9);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(10);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(11);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");register_val=read_reg_ret(12);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 5-12 Shows 6:4=001 gain =1");//ALL BITS EFFECT RLD 13-14 ******
//b1111 1111=255write_reg(13, 255);
write_reg(14, 255);register_val=read_reg_ret(13);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 13 Shows ALL pos BITS EFFECT RLD");register_val=read_reg_ret(14);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 14 Shows ALL neg BITS EFFECT RLD");//Lead off Sense pos, neg, flip
//0000 0000 = 0 = turn offwrite_reg(15, 0);
write_reg(16, 0);
write_reg(17, 0);register_val=read_reg_ret(15);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 15 Shows sens pos. off");register_val=read_reg_ret(16);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 16 Shows sens neg. off");register_val=read_reg_ret(17);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 17 Shows sens flip. off");//lead off status registers 18 &19
//read only//GPIO & Other
//20-25write_reg(20, 15);//GPIO = 15=1111 = input status registers will show values.
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 20 GPIO = 0 = output");
write_reg(21, 0);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 21 Pace");
write_reg(22, 0);//RESPETORY = 0 = respetory circuit off
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 22 Shows RESPETORY = 0 = respetory circuit off");//reg 23 has read continuous it cant be set till
//all other registers be setwrite_reg(24, 0);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 24 WCT1");
write_reg(25, 0);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 25 WCT2");write_reg(23, 0);
SerialUSB.print(register_val,BIN);
SerialUSB.println(" Register 23 Config4");//rdatac shows continuous conversion after start doen't it ignore commands?
rdatac();}
void read_n_print_9_words(void){
status_0=sclk_out_word_ret24();
SerialUSB.println(status_0, BIN);sample_1=sclk_out_word_ret24();
SerialUSB.println(sample_1, BIN);
sample_2=sclk_out_word_ret24();
SerialUSB.println(sample_2, BIN);
sample_3=sclk_out_word_ret24();
SerialUSB.println(sample_3, BIN);
sample_4=sclk_out_word_ret24();
SerialUSB.println(sample_4, BIN);
sample_5=sclk_out_word_ret24();
SerialUSB.println(sample_5, BIN);
sample_6=sclk_out_word_ret24();
SerialUSB.println(sample_6, BIN);
sample_7=sclk_out_word_ret24();
SerialUSB.println(sample_7, BIN);
sample_8=sclk_out_word_ret24();
SerialUSB.println(sample_8, BIN);}
void read_9_words_print_status(void){
status_0=sclk_out_word_ret24();
SerialUSB.println(status_0, BIN);
sample_1=sclk_out_word_ret24();
sample_2=sclk_out_word_ret24();
sample_3=sclk_out_word_ret24();
sample_4=sclk_out_word_ret24();
sample_5=sclk_out_word_ret24();
sample_6=sclk_out_word_ret24();
sample_7=sclk_out_word_ret24();
sample_8=sclk_out_word_ret24();}