void updateChannelData(){ byte inByte; int byteCounter = 0; int numChan = 4; //assume 4 channel. If needed, it automatically changes to 16 automatically in a later block. long stat_1[1]; channelData[4] = 0; if(digitalRead(ADS_DRDY) == LOW){ digitalWrite(CS_ADS, LOW); // open SPI // READ CHANNEL DATA FROM FIRST ADS for(int i=0; i<1; i++){ // read 3 byte status register from ADS 1 (1100+LOFF_STATP+LOFF_STATN+GPIO[7:4]) inByte = SPI.transfer(0x00); stat_1[i] = (stat_1[i]<<8) | inByte; } for(int i = 0; i < numChan; i++){ for(int j=0; j < 3; j++){ // read 24 bits of channel data from 1st ADS in 8 3 byte chunks inByte = SPI.transfer(0x00); channelData[i] = (channelData[i]<<8) | inByte; // Int data array } } digitalWrite(CS_ADS, HIGH); // close SPI //reformat the numbers for(int i = 0; i < numChan; i++){ if(((channelData[i] & 0x800000) >> 23) == 1){ channelData[i] = channelData[i] - 2^24; channelData[i] |= 0xFF000000; ads[i] = channelData[i]; }else{ channelData[i] &= 0x00FFFFFF; ads[i] = channelData[i]; } } for(int i = 0; i < 1; i++){ if(bitRead(stat_1[i],23) == 1){ stat_1[i] |= 0xFF000000; } else{ stat_1[i] &= 0x00FFFFFF; } Serial.println(stat_1[i], HEX); } printChannelData(); } } // ------------------------------- Print Channel Data ------------------------------------- void printChannelData(){ // Serial.println(" "); for(int i = 0; i < 4; i++){ // Serial.println(channelData[i],HEX); // Serial.println(channelData[i],DEC); Serial.println(ads[i]*((2*4.5/24)/(2^23 - 1)),DEC); } Serial.println(); }