Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MPL3115A2 by
Diff: MPL3115A2.cpp
- Revision:
 - 4:fdf14a259af8
 - Parent:
 - 3:a2f1752add9a
 - Child:
 - 5:9edec5ee8bf4
 
diff -r a2f1752add9a -r fdf14a259af8 MPL3115A2.cpp
--- 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);
    