mbed library to interface a Texas Instruments' ADS7828, 12-bits, 8-channels, I2C interfaced ADC

Dependents:   ADS7828_demo

Revision:
3:abbfd9c7f30c
Parent:
2:2ff328d8e4dd
--- a/ADS7828.cpp	Tue Dec 30 14:41:54 2014 +0000
+++ b/ADS7828.cpp	Tue Dec 30 18:45:23 2014 +0000
@@ -1,19 +1,27 @@
 /***************************************************************************
-    ADS7828.CPP
-    Implementation file for library ADS7828     
-    The ADS7828 is a 12-bits, 8-channels, I2C-interfaced from Texas Instruments
-    
-    (c) 2014 - By Francesco Adamo, Italy
-*****************************************************************************/
+ * @author Francesco Adamo
+ *
+ * @section LICENSE
+ *
+ * Copyright (c) 2014 Francesco Adamo
+ *
+ * @section DESCRIPTION
+ *
+ *  ADS7828.CPP
+ *  Implementation file for library ADS7828     
+ *  The ADS7828 is a 12-bits, 8-channels, I2C-interfaced from Texas Instruments
+ *   
+ *  (c) 2014 - By Francesco Adamo, Italy
+ ****************************************************************************/
 
 #include "mbed.h"
 #include "ADS7828.h"
 
-// Constructor
+// Default constructor
 ADS7828::ADS7828(PinName sda, PinName scl) : _i2c(sda, scl) {
     _i2c.frequency(100000);  /* Default I2C clock frequency = 100 kHz, Normal Mode */
-    address = ADS7828_BASE_ADDRESS;
-    VFSR = 2.5F;
+    address = ADS7828_BASE_ADDRESS; // ADS7828 address with pins A0 and A1 connected to ground
+    VFSR = 2.5F;    // Default VFSR (valid if VREF pin is unconnected)
 }
 
 // Constructor overload
@@ -30,7 +38,6 @@
     VFSR = 2.5F;
 }
 
-
 // Constructor overload
 ADS7828::ADS7828(PinName sda, PinName scl, int freq, char subAddress, double VREF) : _i2c(sda, scl) {
     _i2c.frequency(freq);  /* I2C clock frequency = set to input value */
@@ -51,10 +58,10 @@
     if (ack)
         return -1;
     else
-        return D[0] << 8 | D[1];
+        return (int) (D[0] << 8 | D[1]);
 }
 
-// Read a raw value from a given channel
+// Read a value from a given channel and scales it to VFSR
 double ADS7828::readAnalogValue(char mode, char channel) {
     char command, D[2], ack;
     
@@ -67,5 +74,5 @@
     if (ack)
         return -1;
     else
-        return VFSR/4096*(D[0] << 8 | D[1]);
+        return VFSR/4096*((int) (D[0] << 8 | D[1]));
 }
\ No newline at end of file