altb_pmic / Mbed 2 deprecated MS5611_2

Dependencies:   mbed

Revision:
1:a94ff5f08fd7
Parent:
0:7c23db660183
Child:
2:4d9204790be1
diff -r 7c23db660183 -r a94ff5f08fd7 main.cpp
--- a/main.cpp	Tue Feb 18 14:23:41 2020 +0000
+++ b/main.cpp	Fri Feb 21 07:30:50 2020 +0000
@@ -6,6 +6,16 @@
 from the MS5611 sensor.  It has been modified from the MS507 sensor library with 
 the different calculations that the MS5611 requires.  Otherwise, this library is
 identical to the MS5607
+------------
+IndNav: Made adaptions, even though, the original works well, problem:
+the original has a delay of 8ms from writing to reading (see line 73 in MS5611I2C.h)
+Solution: seperate write and read in 2 processes (hene's hint):
+    - write at end of data_read thread, without waiting
+    - at beginning of next call, read the data
+since there are 2 seperate reading/writings (one for pressure(altitude), one for Temperature -and we need both!)
+toggle the 2 processes, this results, that only every 2nd pressure/altitude value is a new value!
+
+altb 20.2.2020
 */
 #include "mbed.h"
  
@@ -14,9 +24,12 @@
 #include "MS5611I2C.h"
  
 Serial pc(USBTX, USBRX);                   // local terminal interface
- 
+Timer timer;
+
 int main() {
     pc.baud(115200);                        // set up USB serial speed
+    timer.reset();
+    timer.start();
     //Only uncomment the I2C or SPI version.
     //MS5611SPI ms5611(p11, p12, p13, p10);
     //MS5611I2C ms5611(p9, p10, false);
@@ -26,9 +39,16 @@
     //Print the Coefficients from the 
     ms5611.printCoefficients();
     while(1){
-    printf("Pressure = %.0f Pa \r\n", ms5611.getPressure());
-    printf("Temperature = %.2f degC \r\n", ms5611.getTemperature());
-    printf("Altitude = %.2f m \r\n", ms5611.getAltitude());
-    wait(.5);
+        timer.reset();
+//        float dum2 = ms5611.getTemperature();
+//        float dum3 = ms5611.getAltitude();
+//        printf("10 Durchlaeufe: %f sec \r\n", T);
+//        printf("Pressure = %.0f Pa \r\n", ms5611.getPressure());
+//        printf("Temperature = %.2f degC \r\n", ms5611.getTemperature());
+        ms5611.getAltitude_toggle_Temp_write();
+        wait_ms(100);
+        printf("Altitude = %.2f m \r\n", ms5611.getAltitude_toggle_Temp_read());
+        float T = timer.read();
+        wait(1.0);
     }
 }
\ No newline at end of file