Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Mon Jul 22 10:12:44 2019 +0000
Parent:
2:9931ca41f17d
Commit message:
This driver was completed and tested ( NUCLEO-L152RE ), it works as expected.

Changed in this revision

ADS101X.cpp Show annotated file Show diff for this revision Revisions of this file
ADS101X.h Show annotated file Show diff for this revision Revisions of this file
--- a/ADS101X.cpp	Mon Jul 22 09:48:39 2019 +0000
+++ b/ADS101X.cpp	Mon Jul 22 10:12:44 2019 +0000
@@ -1,6 +1,6 @@
 /**
  * @brief       ADS101X.cpp
- * @details     Capacitive digital sensor for relative humidity and temperature.
+ * @details     Ultra-Small, Low-Power, I2C-Compatible, 3.3-kSPS, 12-Bit ADCs. With Internal Reference, Oscillator, and Programmable Comparator.
  *              Function file.
  *
  *
@@ -11,7 +11,7 @@
  * @version     22/July/2019    The ORIGIN
  * @pre         N/A.
  * @warning     N/A
- * @pre         This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ). All rights reserved.
+ * @pre         This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
  */
 
 #include "ADS101X.h"
--- a/ADS101X.h	Mon Jul 22 09:48:39 2019 +0000
+++ b/ADS101X.h	Mon Jul 22 10:12:44 2019 +0000
@@ -7,8 +7,8 @@
  * @return      N/A
  *
  * @author      Manuel Caballero
- * @date        17/July/2019
- * @version     17/July/2019    The ORIGIN
+ * @date        22/July/2019
+ * @version     22/July/2019    The ORIGIN
  * @pre         N/A.
  * @warning     N/A
  * @pre         This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
@@ -22,7 +22,115 @@
 /**
     Example:
 @code
+#include "mbed.h"
+#include "ADS101X.h"
 
+ADS101X myADS101X ( I2C_SDA, I2C_SCL, ADS101X::ADS101X_ADDRESS_GND, 400000, ADS101X::DEVICE_ADS1015 );   // I2C_SDA | I2C_SCL | DEVICE_ADS1015
+Serial pc         ( USBTX, USBRX );                                             // tx, rx
+
+DigitalOut  myled   ( LED1 );
+Ticker      newAction;
+
+
+//@brief Constants.
+
+
+//@brief Variables.
+volatile uint32_t myState;                                                      // State that indicates when to perform a new sample    
+
+
+//@brief   FUNCTION PROTOTYPES
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    ADS101X::ADS101X_status_t aux;
+    ADS101X::ADS101X_data_t   myADS101X_Data;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // Perform a softreset   
+    aux  =   myADS101X.ADS101X_SoftReset  ();
+    wait_ms ( 500U );
+
+    // Input multiplexor configuration ( channels ): AINp = AIN0 | AINn = GND  
+    myADS101X_Data.mux  =   ADS101X::CONFIG_MUX_AINP_AIN0_AND_AINN_GND;
+    aux  =   myADS101X.ADS101X_SetMux  ( myADS101X_Data );
+
+    // Gain: ±4.096V  
+    myADS101X_Data.pga  =   ADS101X::CONFIG_PGA_FSR_4_096_V;
+    aux  =   myADS101X.ADS101X_SetGain  ( myADS101X_Data );
+
+    // Mode: Single-shot 
+    myADS101X_Data.mode  =   ADS101X::CONFIG_MODE_SINGLE_SHOT;
+    aux  =   myADS101X.ADS101X_SetMode  ( myADS101X_Data );
+
+    // Data rate: 1600 SPS  
+    myADS101X_Data.dr  =   ADS101X::CONFIG_DR_1600_SPS;
+    aux  =   myADS101X.ADS101X_SetDataRate  ( myADS101X_Data );
+
+    // Comparator: Disabled 
+    myADS101X_Data.comp_que  =   ADS101X::CONFIG_COMP_QUE_DISABLED;
+    aux  =   myADS101X.ADS101X_SetComparator  ( myADS101X_Data );
+
+    myState  =   0UL;                                                           // Reset the variable
+    newAction.attach( &changeDATA, 1U );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1UL ) {
+            myled = 1U;
+
+            // Trigger a new conversion  
+            aux  =   myADS101X.ADS101X_StartSingleConversion ();
+
+            // Wait until the conversion is completed  
+            do {
+                aux  =   myADS101X.ADS101X_GetOS ( &myADS101X_Data );
+            } while( ( myADS101X_Data.os & ADS101X::CONFIG_OS_MASK ) == ADS101X::CONFIG_OS_BUSY );  // [TODO] Too dangerous! the uC may get stuck here
+            // [WORKAROUND] Insert a counter.
+            // Get the result  
+            aux  =   myADS101X.ADS101X_GetConversion ( &myADS101X_Data );
+
+            // Send data through the UART    
+            pc.printf ( "V: %d mV\r\n", (int32_t)( 1000 * myADS101X_Data.conversion ) );
+
+
+            // Reset the variables   
+            myState  =   0UL;
+            myled    =   0U;
+        }
+    }
+}
+
+
+// @brief       changeDATA ( void  )
+//
+// @details     It changes myState variable
+//
+// @param[in]    N/A
+//
+// @param[out]   N/A.
+//
+// @return       N/A.
+//
+// @author      Manuel Caballero
+// @date        22/July/2019
+// @version     22/July/2019   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+void changeDATA ( void )
+{
+    myState  =   1UL;
+}
 @endcode
 */
 
@@ -360,7 +468,7 @@
 private:
     I2C                 _i2c;
     uint32_t            _ADS101X_Addr;
-    ADS101X_device_t    _device;                 
+    ADS101X_device_t    _device;
 };
 
 #endif