Library for the ADS1015 and ADS1115 ADCS

Fork of ADS1015 by Momo-Medical

Revision:
18:4b4e3446cdd4
Parent:
16:a9e5edacbaf7
Parent:
15:e659b715ed89
Child:
20:277793ce35b2
diff -r 7c2804e3dbaf -r 4b4e3446cdd4 Adafruit_ADS1015.cpp
--- a/Adafruit_ADS1015.cpp	Thu Jun 21 11:55:16 2018 +0000
+++ b/Adafruit_ADS1015.cpp	Thu Jun 21 11:58:17 2018 +0000
@@ -313,6 +313,68 @@
         return (int16_t)res;
     }
 }
+int16_t * Adafruit_ADS1015::readADC_Differential_DoubleEnded(){
+    
+    uint16_t temp_res;
+    static int16_t results[2];
+    
+    uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
+                      ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
+                      ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
+                      ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
+                      ADS1015_REG_CONFIG_DR_3300SPS   | // 1600(ADS1015) or 250(ADS1115) samples per second (default)
+                      ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)
+
+    // Set PGA/voltage range
+    config |= m_gain;
+
+    // Set channels
+    config |= ADS1015_REG_CONFIG_MUX_DIFF_0_3;          // AIN0 = P, AIN1 = N
+
+    // Set 'start single-conversion' bit
+    config |= ADS1015_REG_CONFIG_OS_SINGLE;
+    
+//    // Read the first 
+//    temp_res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
+//    
+//    if (m_bitShift != 0) {
+//        // Shift 12-bit results right 4 bits for the ADS1015,
+//        // making sure we keep the sign bit intact
+//        if (temp_res > 0x07FF) {
+//            // negative number - extend the sign to 16th bit
+//            temp_res |= 0xF000;
+//        }  
+//    }
+//    results[0] = temp_res;
+    
+
+    // Write config register to the ADC
+    writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
+
+    // Wait for the conversion to complete
+    wait_us(m_conversionDelay);
+    
+    // Read the conversion results
+    temp_res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
+    
+    if (m_bitShift != 0) {
+        // Shift 12-bit results right 4 bits for the ADS1015,
+        // making sure we keep the sign bit intact
+        if (temp_res > 0x07FF) {
+            // negative number - extend the sign to 16th bit
+            temp_res |= 0xF000;
+        }  
+    }
+    results[1] |= (int16_t) temp_res;
+    
+    //config |= ADS1015_REG_CONFIG_MUX_DIFF_1_3; 
+//    
+//    // Write config register to the ADC
+//    writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
+    
+    return results;
+} 
+
 /**************************************************************************/
 /*!
     @brief  Sets up the comparator to operate in basic mode, causing the