altb_pmic / Mbed 2 deprecated MS5611_2

Dependencies:   mbed

Committer:
altb2
Date:
Tue May 19 13:13:03 2020 +0000
Revision:
2:4d9204790be1
Parent:
1:a94ff5f08fd7
MS56 Baro-sensor with toggling Temper. and pressure overe i2c;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
altb2 0:7c23db660183 1 /* MS5611 Pressure sensor example
altb2 0:7c23db660183 2 Aerodyne Labs
altb2 0:7c23db660183 3 2014
altb2 0:7c23db660183 4
altb2 0:7c23db660183 5 This example uses the MS511 Library to read the temperature and pressure readings
altb2 0:7c23db660183 6 from the MS5611 sensor. It has been modified from the MS507 sensor library with
altb2 0:7c23db660183 7 the different calculations that the MS5611 requires. Otherwise, this library is
altb2 0:7c23db660183 8 identical to the MS5607
altb2 1:a94ff5f08fd7 9 ------------
altb2 1:a94ff5f08fd7 10 IndNav: Made adaptions, even though, the original works well, problem:
altb2 1:a94ff5f08fd7 11 the original has a delay of 8ms from writing to reading (see line 73 in MS5611I2C.h)
altb2 1:a94ff5f08fd7 12 Solution: seperate write and read in 2 processes (hene's hint):
altb2 1:a94ff5f08fd7 13 - write at end of data_read thread, without waiting
altb2 1:a94ff5f08fd7 14 - at beginning of next call, read the data
altb2 1:a94ff5f08fd7 15 since there are 2 seperate reading/writings (one for pressure(altitude), one for Temperature -and we need both!)
altb2 1:a94ff5f08fd7 16 toggle the 2 processes, this results, that only every 2nd pressure/altitude value is a new value!
altb2 1:a94ff5f08fd7 17
altb2 1:a94ff5f08fd7 18 altb 20.2.2020
altb2 0:7c23db660183 19 */
altb2 0:7c23db660183 20 #include "mbed.h"
altb2 0:7c23db660183 21
altb2 0:7c23db660183 22 //Only uncomment the one needed.
altb2 0:7c23db660183 23 //#include "MS5611SPI.h"
altb2 0:7c23db660183 24 #include "MS5611I2C.h"
altb2 0:7c23db660183 25
altb2 0:7c23db660183 26 Serial pc(USBTX, USBRX); // local terminal interface
altb2 1:a94ff5f08fd7 27 Timer timer;
altb2 1:a94ff5f08fd7 28
altb2 0:7c23db660183 29 int main() {
altb2 0:7c23db660183 30 pc.baud(115200); // set up USB serial speed
altb2 1:a94ff5f08fd7 31 timer.reset();
altb2 1:a94ff5f08fd7 32 timer.start();
altb2 0:7c23db660183 33 //Only uncomment the I2C or SPI version.
altb2 0:7c23db660183 34 //MS5611SPI ms5611(p11, p12, p13, p10);
altb2 0:7c23db660183 35 //MS5611I2C ms5611(p9, p10, false);
altb2 0:7c23db660183 36 //PB_9 and PB_8 for Nucleo boards
altb2 0:7c23db660183 37 I2C i2c(PB_3,PB_10);
altb2 0:7c23db660183 38 MS5611I2C ms5611(i2c, false);
altb2 0:7c23db660183 39 //Print the Coefficients from the
altb2 0:7c23db660183 40 ms5611.printCoefficients();
altb2 0:7c23db660183 41 while(1){
altb2 1:a94ff5f08fd7 42 timer.reset();
altb2 1:a94ff5f08fd7 43 // float dum2 = ms5611.getTemperature();
altb2 1:a94ff5f08fd7 44 // float dum3 = ms5611.getAltitude();
altb2 1:a94ff5f08fd7 45 // printf("10 Durchlaeufe: %f sec \r\n", T);
altb2 1:a94ff5f08fd7 46 // printf("Pressure = %.0f Pa \r\n", ms5611.getPressure());
altb2 1:a94ff5f08fd7 47 // printf("Temperature = %.2f degC \r\n", ms5611.getTemperature());
altb2 1:a94ff5f08fd7 48 ms5611.getAltitude_toggle_Temp_write();
altb2 1:a94ff5f08fd7 49 wait_ms(100);
altb2 1:a94ff5f08fd7 50 printf("Altitude = %.2f m \r\n", ms5611.getAltitude_toggle_Temp_read());
altb2 2:4d9204790be1 51 printf("Altitude = %.2f m \r\n", ms5611.getAltitude());
altb2 1:a94ff5f08fd7 52 float T = timer.read();
altb2 1:a94ff5f08fd7 53 wait(1.0);
altb2 0:7c23db660183 54 }
altb2 0:7c23db660183 55 }