High resolution barometer and altimeter using i2c mode

Dependents:   Q2_Stabi

Fork of ms5611 by Kevin Braun

Revision:
7:90ee2168baa7
Parent:
6:41c370fa1f7b
Child:
8:461f68bc94f2
diff -r 41c370fa1f7b -r 90ee2168baa7 ms5611.cpp
--- a/ms5611.cpp	Mon Jun 24 19:11:28 2013 +0000
+++ b/ms5611.cpp	Mon Dec 22 23:38:34 2014 +0000
@@ -24,10 +24,26 @@
 uint32_t C[8];                  //coefficient storage
 
 //--------------------------------------------------------------------------------------------------------------------------------------//
-// Constructor and destructor
+// Constructor and destructor - default to be compatible with legacy m5611 driver
 
 ms5611::ms5611(PinName sda, PinName scl)  : _i2c(sda, scl) {
         _i2c.frequency(400000);
+        _i2cWAddr = MS5611_ADDR_W;
+        _i2cRAddr = MS5611_ADDR_R;
+}
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+// Constructor and destructor - new, to allow for user to select i2c address based on CSB pin
+
+ms5611::ms5611(PinName sda, PinName scl, CSBpolarity CSBpin)  : _i2c(sda, scl) {
+        _i2c.frequency(400000);
+        _i2cWAddr = MS5611_ADDR_W;
+        _i2cRAddr = MS5611_ADDR_R;
+        if(CSBpin == CSBpin_1) {
+            _i2cWAddr -= 2;
+            _i2cRAddr -= 2;
+        
+        }
 }
 
 //********************************************************
@@ -40,9 +56,9 @@
     int twst;
     _i2c.start();
     if(readMode == true) {
-        twst = m_i2c_write(MS5611_ADDR_R);
+        twst = m_i2c_write(_i2cRAddr);
     } else {
-        twst = m_i2c_write(MS5611_ADDR_W);
+        twst = m_i2c_write(_i2cWAddr);
     }
     return(twst);
 }
@@ -142,7 +158,7 @@
     }
     m_i2c_send(MS5611_CMD_ADC_READ);
     
-    ret = _i2c.read(MS5611_ADDR_R, cobuf, 3, false);
+    ret = _i2c.read(_i2cRAddr, cobuf, 3, false);
     if(ret) printf("\n*** ms5611 ADC Read Error ");
     temp = (cobuf[0] << 16) + (cobuf[1] << 8) + cobuf[2];
     return temp;
@@ -161,7 +177,7 @@
     cobuf[0] = 0;
     cobuf[1] = 0;
     m_i2c_send(MS5611_CMD_PROM_RD + coef_num * 2); // send PROM READ command
-    ret = _i2c.read(MS5611_ADDR_R, cobuf, 2, false);
+    ret = _i2c.read(_i2cRAddr, cobuf, 2, false);
     if(ret) printf("\n*** ms5611 PROM Read Error ");
     rC = cobuf[0] * 256 + cobuf[1];
     return rC;