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 May 30 07:27:24 2013 +0000
Parent:
3:a2f1752add9a
Child:
5:9edec5ee8bf4
Commit message:
Added and tested the data acquisition using Interrupt. Added code for Altimeter trigger Interrupt but not yet tested.

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	Wed May 29 11:56:52 2013 +0000
+++ b/MPL3115A2.cpp	Thu May 30 07:27:24 2013 +0000
@@ -3,6 +3,7 @@
 #define REG_WHO_AM_I        0x0C        // return 0xC4 by default
 #define REG_STATUS          0x00
 #define REG_CTRL_REG_1      0x26
+#define REG_CTRL_REG_3      0x28
 #define REG_CTRL_REG_4      0x29
 #define REG_CTRL_REG_5      0x2A
 #define REG_PRESSURE_MSB    0x01        // 3 byte pressure data
@@ -36,6 +37,11 @@
 MPL3115A2::MPL3115A2(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
     MPL3115A2_mode = BAROMETRIC_MODE;
     MPL3115A2_oversampling = OVERSAMPLE_RATIO_1;
+    //
+    user1_fptr = NULL;
+    user2_fptr = NULL;
+    MPL3115A2_Int1.fall( NULL);
+    MPL3115A2_Int2.fall( NULL);
 }
 
 void MPL3115A2::Reset( void)
@@ -55,21 +61,18 @@
     unsigned char dt[5];
     unsigned char data[2];
     
+    // Soft Reset
     Reset();
     
-    /*
-    ** Read contents of CTRL_REG_1
-    ** Clear SBYB mask while holding all other values of CTRL_REG_1.
-    ** To put part into Standby mode
-    */
     Standby();
     
-    /*
-    ** Clear all interrupts by reading the output registers.
-    ** Activate sensor in Altimeter mode.
-    */
+    // Clear all interrupts by reading the output registers.
     readRegs( REG_ALTIMETER_MSB, &dt[0], 5);
     getStatus();
+    // Configure INT active low and pullup
+    data[0] = REG_CTRL_REG_3;
+    data[1] = 0x00;
+    writeRegs(data, 2);    
     // Enable Interrupt fot data ready
     data[0] = REG_CTRL_REG_4;
     data[1] = 0x80;
@@ -78,12 +81,20 @@
     data[0] = REG_CTRL_REG_5;
     data[1] = 0x00;
     writeRegs(data, 2);    
+    data[0] = REG_PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);    
 
-    /*
-    ** Configure the OverSampling rate, Altimeter mode and set the sensor Active
-    */
+    // Configure the OverSampling rate, Altimeter/Barometer mode and set the sensor Active
     data[0] = REG_CTRL_REG_1;
-    data[1] = 0x81 | (OS<<3);
+    data[1] = (OS<<3);
+    //
+    if (MPL3115A2_mode == BAROMETRIC_MODE)
+        data[1] &= 0x7F;
+    else
+        data[1] |= 0x80;
+    //
+    data[1] |= 0x01; 
     writeRegs(data, 2);    
 
     user2_fptr = fptr;
@@ -115,14 +126,16 @@
     getStatus();
 
     // Write Target and Window Values
-    data[0] = (level<<8);
-    data[1] = (level&0xFF);
-    writeRegs( data, 2);
+    dt[0] = REG_P_TGT_MSB;
+    dt[1] = (level>>8);
+    dt[2] = (level&0xFF);
+    writeRegs( dt, 3);
     
     // Window values are zero
-    data[0] = 0;
-    data[1] = 0;
-    writeRegs( data, 2);
+    dt[0] = REG_P_WND_MSB;
+    dt[1] = 0;
+    dt[2] = 0;
+    writeRegs( dt, 3);
 
     // Enable Pressure Threshold interrupt
     data[0] = REG_CTRL_REG_4;
@@ -132,8 +145,13 @@
     data[0] = REG_CTRL_REG_5;
     data[1] = 0x08;
     writeRegs( data, 2);
-
-    Active();
+    data[0] = REG_PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);    
+    // Configure the OverSampling rate, Altimeter mode and set the sensor Active
+    data[0] = REG_CTRL_REG_1;
+    data[1] = 0x81 | (MPL3115A2_oversampling<<3);    
+    writeRegs(data, 2);    
 
     user1_fptr = fptr;
     MPL3115A2_Int1.fall( this, &MPL3115A2::AltitudeTrg_IRQ);
--- a/MPL3115A2.h	Wed May 29 11:56:52 2013 +0000
+++ b/MPL3115A2.h	Thu May 30 07:27:24 2013 +0000
@@ -145,9 +145,9 @@
     void DataReady( void(*fptr)(void), unsigned char OS);
 
     /**
-    * Configure the sensor to streaming data using Interrupt
+    * Configure the sensor to generate an Interrupt crossing the center threshold
     *
-    * @param user functin callback, oversampling values. See MPL3115A2.h
+    * @param user functin callback, level in meter
     * @return none
     */
     void AltitudeTrigger( void(*fptr)(void), unsigned short level);