Manuel Caballero / HDC2080

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Tue Nov 19 18:54:52 2019 +0000
Parent:
2:d6cde3037eac
Commit message:
The driver was completed and tested ( NUCLEOL476RG ) and it works as expected.

Changed in this revision

HDC2080.cpp Show annotated file Show diff for this revision Revisions of this file
HDC2080.h Show annotated file Show diff for this revision Revisions of this file
--- a/HDC2080.cpp	Tue Nov 19 10:55:47 2019 +0000
+++ b/HDC2080.cpp	Tue Nov 19 18:54:52 2019 +0000
@@ -103,7 +103,7 @@
     aux      =   HDC2080_GetRawTemperature  ( &(*myTemperature) );
 
     /* Parse data   */
-    myTemperature->temperature  =   ( (double)( myTemperature->rawTemperature ) / 65536.0 ) * 165.0 - 40.0;
+    myTemperature->temperature  =   ( ( myTemperature->rawTemperature ) / 65536.0 ) * 165.0 - 40.0;
 
 
     return   aux;
@@ -184,7 +184,7 @@
     aux      =   HDC2080_GetRawHumidity  ( &(*myHumidity) );
 
     /* Parse data   */
-    myHumidity->humidity    =   ( (double)( myHumidity->rawHumidity ) / 65536.0 ) * 100.0;
+    myHumidity->humidity    =   ( ( myHumidity->rawHumidity ) / 65536.0 ) * 100.0;
 
 
     return   aux;
--- a/HDC2080.h	Tue Nov 19 10:55:47 2019 +0000
+++ b/HDC2080.h	Tue Nov 19 18:54:52 2019 +0000
@@ -22,7 +22,129 @@
 /**
     Example:
 @code
+#include "mbed.h"
+#include "HDC2080.h"
 
+HDC2080 myHDC2080 ( I2C_SDA, I2C_SCL, HDC2080::HDC2080_ADDRESS_GND, 400000 );
+Serial pc         ( USBTX, USBRX );
+
+DigitalOut  myled ( LED1 );
+Ticker      newReading;
+
+
+//@brief Variables.
+uint32_t    myState = 0;
+
+//@brief   FUNCTION PROTOTYPES
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    HDC2080::HDC2080_data_t   myHDC2080_Data;
+    HDC2080::HDC2080_status_t aux;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // Perform a software reset
+    aux  =   myHDC2080.HDC2080_SetSoftReset ();
+    do {
+        aux  =   myHDC2080.HDC2080_GetSoftReset ( &myHDC2080_Data );
+    } while( ( myHDC2080_Data.soft_res & HDC2080::RESET_DRDY_INT_CONF_SOFT_RES_MASK ) == HDC2080::RESET_DRDY_INT_CONF_SOFT_RES_RESET );
+
+    // Get Manufacturer IDs
+    aux  =   myHDC2080.HDC2080_GetManufacturerID ( &myHDC2080_Data );
+
+    // Get device IDs
+    aux  =   myHDC2080.HDC2080_GetDeviceID ( &myHDC2080_Data );
+    pc.printf( "Manufacturer ID: %x | Device ID: %x\r\n", myHDC2080_Data.manufacturer_id, myHDC2080_Data.device_id );
+
+    // Auto measurement mode: Disable (  Initiate measurement via I2C )
+    myHDC2080_Data.amm   =   HDC2080::RESET_DRDY_INT_CONF_AMM_DISABLED;
+    aux  =   myHDC2080.HDC2080_SetAutoMeasurementMode ( myHDC2080_Data );
+
+    // Heater off
+    myHDC2080_Data.heater_en     =   HDC2080::RESET_DRDY_INT_CONF_HEAT_EN_OFF;
+    aux  =   myHDC2080.HDC2080_SetHeaterMode ( myHDC2080_Data );
+
+    // DRDY/INT_EN pin configuration: High Z
+    myHDC2080_Data.drdy_intEn    =   HDC2080::RESET_DRDY_INT_CONF_DRDY_INT_EN_HIGH_Z;
+    aux  =   myHDC2080.HDC2080_SetHeaterMode ( myHDC2080_Data );
+
+    // All interrupts are disabled
+    myHDC2080_Data.drdy_enable  =    HDC2080::INTERRUPT_DRDY_DRDY_ENABLE_INTERRUPT_DISABLE;
+    myHDC2080_Data.th_enable    =    HDC2080::INTERRUPT_DRDY_TH_ENABLE_INTERRUPT_DISABLE;
+    myHDC2080_Data.tl_enable    =    HDC2080::INTERRUPT_DRDY_TL_ENABLE_INTERRUPT_DISABLE;
+    myHDC2080_Data.hh_enable    =    HDC2080::INTERRUPT_DRDY_HH_ENABLE_INTERRUPT_DISABLE;
+    myHDC2080_Data.hl_enable    =    HDC2080::INTERRUPT_DRDY_HL_ENABLE_INTERRUPT_DISABLE;
+    aux                         =    myHDC2080.HDC2080_SetInterruptConfiguration ( myHDC2080_Data );
+
+    // Measurement configuration: Humidity and Temperature 14-bit resolution. Both measurement enabled
+    myHDC2080_Data.tres         =    HDC2080::MEASUREMENT_CONF_TRES_14_BIT;
+    myHDC2080_Data.hres         =    HDC2080::MEASUREMENT_CONF_HRES_14_BIT;
+    myHDC2080_Data.meas_conf    =    HDC2080::MEASUREMENT_CONF_MEAS_CONF_HUMIDITY_TEMPERATURE;
+    aux                         =    myHDC2080.HDC2080_SetMeasurementConf ( myHDC2080_Data );
+
+    newReading.attach( &changeDATA, 1 );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        myled = 1;
+
+        if ( myState == 1 ) {
+            // Trigegr a new sample
+            aux  =   myHDC2080.HDC2080_StartMeasurementTrigger ();
+
+            // Wait until the conversion is finished
+            do {
+                aux      =   myHDC2080.HDC2080_GetMeasurementTrigger ( &myHDC2080_Data );
+            } while( ( myHDC2080_Data.meas_trig & HDC2080::MEASUREMENT_CONF_MEAS_TRIG_MASK ) != HDC2080::MEASUREMENT_CONF_MEAS_TRIG_NO_ACTION );  // [TODO] Dangerous!!! The uC may get stuck here if something goes wrong!
+                                                                                                                                // [WORKAROUND] Insert a counter.
+
+            // Get temperature
+            aux  =   myHDC2080.HDC2080_GetTemperature ( &myHDC2080_Data );
+
+            // Get humidity
+            aux  =   myHDC2080.HDC2080_GetHumidity ( &myHDC2080_Data );
+
+            // Transmit result over the UART
+            pc.printf( "T: %0.2f C | RH: %0.2f %%\r\n", myHDC2080_Data.temperature, myHDC2080_Data.humidity  );
+
+            myState  =   0;                                                     // Reset the variable
+        }
+
+        myled = 0;
+    }
+}
+
+// @brief       changeDATA ( void  )
+//
+// @details     It changes myState variable
+//
+// @param[in]    N/A
+//
+// @param[out]   N/A.
+//
+//
+// @return       N/A.
+//
+//
+// @author      Manuel Caballero
+// @date        19/November/2019
+// @version     19/November/2019   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+void changeDATA ( void )
+{
+    myState = 1;
+}
 @endcode
 */