A library for ADS1015 and ADS1115 from Texas Instruments.

Fork of ADS1015 by Arve Seljebu

Files at this revision

API Documentation at this revision

Comitter:
cgoyette
Date:
Tue Jul 17 16:17:50 2018 +0000
Parent:
5:aa277517f0ad
Child:
7:72e307987683
Commit message:
added debug messages;

Changed in this revision

Adafruit_ADS1015.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Adafruit_ADS1015.cpp	Sat Oct 11 08:45:17 2014 +0000
+++ b/Adafruit_ADS1015.cpp	Tue Jul 17 16:17:50 2018 +0000
@@ -32,11 +32,20 @@
 /**************************************************************************/
 void Adafruit_ADS1015::writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value)
 {
+    printf("ADC-wr1\r\n");
     char cmd[3];
     cmd[0] = (char)reg;
+    printf("ADC-wr cmd0=%i\r\n", cmd[0]);
+    printf("ADC-wr2\r\n");
     cmd[1] = (char)(value>>8);
+    printf("ADC-wr cmd1=%i\r\n", cmd[1]);
+    printf("ADC-wr3\r\n");
     cmd[2] = (char)(value & 0xFF);
+    printf("ADC-wr cmd2=%i\r\n", cmd[2]);
+    printf("ADC-wr4\r\n");
+
     m_i2c->write(i2cAddress, cmd, 3);
+    printf("ADC-wr5\r\n");
 }
 
 /**************************************************************************/
@@ -46,10 +55,15 @@
 /**************************************************************************/
 uint16_t Adafruit_ADS1015::readRegister(uint8_t i2cAddress, uint8_t reg)
 {
+    printf("ADC-RR1\r\n");
     char data[2];
+    printf("ADC-RR2\r\n");
     data[0] = reg; // temporary use this to send address to conversion register
+    printf("ADC-RR3\r\n");
     m_i2c->write(i2cAddress, data, 1);
+    printf("ADC-RR4\r\n");
     m_i2c->read(i2cAddress, data, 2);
+    printf("ADC-RR5\r\n");
     return (data[0] << 8 | data [1]);
 }
 
@@ -77,6 +91,7 @@
 {
     // shift 7 bit address 1 left: read expects 8 bit address, see mbed's I2C.h
     m_i2cAddress = i2cAddress << 1;
+    printf("12c-address=%i\r\n", m_i2cAddress);
     m_conversionDelay = ADS1115_CONVERSIONDELAY;
     m_bitShift = 0;
     m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
@@ -110,10 +125,13 @@
 /**************************************************************************/
 uint16_t Adafruit_ADS1015::readADC_SingleEnded(uint8_t channel)
 {
+    printf("ADC1\r\n");
+    printf("channel = %i\r\n", channel);
     if (channel > 3) {
+        printf("ADC2\r\n");
         return 0;
     }
-
+    printf("ADC3\r\n");
     // Start with default values
     uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
                       ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
@@ -123,35 +141,48 @@
                       ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)
 
     // Set PGA/voltage range
+    printf("ADC4\r\n");
     config |= m_gain;
-
+    printf("ADC5\r\n");
     // Set single-ended input channel
     switch (channel) {
         case (0):
+            printf("ADC6\r\n");
             config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
+            printf("ADC7\r\n");
             break;
         case (1):
+            printf("ADC8\r\n");
             config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
+            printf("ADC9\r\n");
             break;
         case (2):
+            printf("ADC10\r\n");
             config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
+            printf("ADC11\r\n");
             break;
         case (3):
+            printf("ADC12\r\n");
             config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
+            printf("ADC13\r\n");
             break;
     }
 
     // Set 'start single-conversion' bit
+    printf("ADC14\r\n");
     config |= ADS1015_REG_CONFIG_OS_SINGLE;
 
     // Write config register to the ADC
+    printf("ADC15\r\n");
     writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
 
     // Wait for the conversion to complete
+    printf("ADC16\r\n");
     wait_ms(m_conversionDelay);
 
     // Read the conversion results
     // Shift 12-bit results right 4 bits for the ADS1015
+    printf("ADC17\r\n");
     return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
 }