Llibrary for the WiGo MPL3115A2, I2C Precision Altimeter sensor.

Dependents:   KL25Z_Batt_Test WIGO_MPL3115A2 Multi-Sensor SPACEmk2 ... more

30/05/2013 Added and tested the data acquisition using Interrupt. Added code for Altimeter trigger Interrupt but not yet tested.

Very basic library. Under development. Need to add in order: 1. IRQ configuration. 2. FIFO mode configuration.

Files at this revision

API Documentation at this revision

Comitter:
clemente
Date:
Thu Aug 22 12:03:19 2013 +0000
Parent:
4:fdf14a259af8
Child:
6:03c24251e500
Commit message:
Added function to read raw data in polling mode. Minor change.

Changed in this revision

MPL3115A2.cpp Show annotated file Show diff for this revision Revisions of this file
MPL3115A2.h Show annotated file Show diff for this revision Revisions of this file
--- a/MPL3115A2.cpp	Thu May 30 07:27:24 2013 +0000
+++ b/MPL3115A2.cpp	Thu Aug 22 12:03:19 2013 +0000
@@ -309,9 +309,9 @@
     float faltm;
     
     /*
-    * dt[0] = Bits 12-19 of 20-bit real-time Pressure sample. (b7-b0)
-    * dt[1] = Bits 4-11 of 20-bit real-time Pressure sample. (b7-b0)
-    * dt[2] = Bits 0-3 of 20-bit real-time Pressure sample (b7-b4)
+    * dt[0] = Bits 12-19 of 20-bit real-time Altitude sample. (b7-b0)
+    * dt[1] = Bits 4-11 of 20-bit real-time Altitude sample. (b7-b0)
+    * dt[2] = Bits 0-3 of 20-bit real-time Altitude sample (b7-b4)
     */
     readRegs( REG_ALTIMETER_MSB, &dt[0], 3);
     altm = (dt[0]<<8) | dt[1];
@@ -377,6 +377,57 @@
 
 }
 
+unsigned int MPL3115A2::getAllDataRaw( unsigned char *dt)
+{
+    if ( MPL3115A2_mode == ALTIMETER_MODE) {
+        getAltimeterRaw( &dt[0]);               // 3 bytes
+    } else {
+        getPressureRaw( &dt[0]);                   // 3 bytes
+    }
+    
+    getTemperatureRaw( &dt[3]);                    // 2 bytes
+    
+    return 1;
+}
+
+unsigned int MPL3115A2::getAltimeterRaw( unsigned char *dt)
+{
+    
+    /*
+    * dt[0] = Bits 12-19 of 20-bit real-time Pressure sample. (b7-b0)
+    * dt[1] = Bits 4-11 of 20-bit real-time Pressure sample. (b7-b0)
+    * dt[2] = Bits 0-3 of 20-bit real-time Pressure sample (b7-b4)
+    */
+    readRegs( REG_ALTIMETER_MSB, &dt[0], 3);
+
+    return 1;
+}
+
+unsigned int  MPL3115A2::getPressureRaw( unsigned char *dt)
+{
+    
+    /*
+    * dt[0] = Bits 12-19 of 20-bit real-time Pressure sample. (b7-b0)
+    * dt[1] = Bits 4-11 of 20-bit real-time Pressure sample. (b7-b0)
+    * dt[2] = Bits 0-3 of 20-bit real-time Pressure sample (b7-b4)
+    */
+    readRegs( REG_PRESSURE_MSB, &dt[0], 3);
+
+    return 1;
+}
+
+unsigned int MPL3115A2::getTemperatureRaw( unsigned char *dt)
+{
+    
+    /*
+    * dt[0] = Bits 4-11 of 16-bit real-time temperature sample. (b7-b0)
+    * dt[1] = Bits 0-3 of 16-bit real-time temperature sample. (b7-b4)
+    */
+    readRegs( REG_TEMP_MSB, &dt[0], 2);
+
+    return 1;
+}
+
 void MPL3115A2::readRegs(int addr, uint8_t * data, int len) {
     char t[1] = {addr};
     m_i2c.write(m_addr, t, 1, true);
--- a/MPL3115A2.h	Thu May 30 07:27:24 2013 +0000
+++ b/MPL3115A2.h	Thu Aug 22 12:03:19 2013 +0000
@@ -84,6 +84,14 @@
     * @returns altimeter value as float
     */
     float getAltimeter( void);
+
+    /**
+    * Get the altimeter value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns          status as 1
+    */
+    unsigned int getAltimeterRaw( unsigned char *dt);
     
     /**
     * Get the pressure value
@@ -91,6 +99,14 @@
     * @returns pressure value as float
     */
     float getPressure( void);
+
+    /**
+    * Get the pressure value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns          status as 1
+    */
+    unsigned int  getPressureRaw( unsigned char *dt);
     
     /**
     * Get the temperature value
@@ -98,6 +114,14 @@
     * @returns temperature value as float
     */
     float getTemperature( void);
+
+    /**
+    * Get the temperature value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns status as 1
+    */
+    unsigned int getTemperatureRaw( unsigned char *dt);
     
     /**
     * Set the Altimeter Mode
@@ -114,12 +138,20 @@
     void Barometric_Mode( void);
     
     /**
-    * Get the altimeter, pressure and temperature values
+    * Get the altimeter or pressure and temperature values
     *
-    * @param array of float f[3]
+    * @param array of float f[2]
     * @returns none
     */
     void getAllData( float *f);
+
+    /**
+    * Get the altimeter or pressure, and temperature values in raw mode
+    *
+    * @param array of unsigned char[5]
+    * @returns staus as 1
+    */    
+    unsigned int getAllDataRaw( unsigned char *dt);
     
     /** 
     * Return if there are date available