Revision 1:b7fffbf481e2, committed 2019-12-25
- Comitter:
- bouaziz
- Date:
- Wed Dec 25 15:12:21 2019 +0000
- Parent:
- 0:5760862143d1
- Commit message:
- TP version 1 ENSA
Changed in this revision
diff -r 5760862143d1 -r b7fffbf481e2 MS5607Base.h
--- a/MS5607Base.h Tue Jul 03 08:57:57 2012 +0000
+++ b/MS5607Base.h Wed Dec 25 15:12:21 2019 +0000
@@ -25,6 +25,18 @@
class MS5607Base {
public:
+ void init(float itemp=0,float ipress=0) {
+ writeCommand(RESET, 3);
+ c1 = readPROM(1);
+ c2 = readPROM(2);
+ c3 = readPROM(3);
+ c4 = readPROM(4);
+ c5 = readPROM(5);
+ c6 = readPROM(6);
+ inittemp = itemp;
+ initpress= ipress;
+ }
+
void printCoefficients() {
printf("%d, %d, %d, %d, %d, %d\n", c1, c2, c3, c4, c5, c6);
}
@@ -38,12 +50,12 @@
}
float getTemperature() {
- int dT = getRawTemperature() - (c5 << 8);
- int temp = 2000 + ((dT * c6) >> 23);
+ int dT = getRawTemperature() - ((0x0FFFF&c5) << 8);
+ int temp = 2000 + (((int64_t)dT * (0x0FFFF&c6)) >> 23);
// 2nd order temperature compensation
if (temp < 2000) {
- int t2 = (int64_t) dT * dT >> 31;
+ int t2 = ((int64_t) dT * dT )>> 31;
temp -= t2;
}
@@ -77,7 +89,7 @@
protected:
int32_t c1, c2, c3, c4, c5, c6;
-
+ float inittemp, initpress;
enum {
RESET = 0x1E,
ADC_READ = 0x00,
@@ -96,23 +108,17 @@
virtual int readPROM(int address) = 0;
virtual int readADC(int command) = 0;
- void init() {
- writeCommand(RESET, 3);
- c1 = readPROM(1);
- c2 = readPROM(2);
- c3 = readPROM(3);
- c4 = readPROM(4);
- c5 = readPROM(5);
- c6 = readPROM(6);
- }
+
float toAltitude(int pressure) {
// Ref. 29124-AltimeterAppNote1.pdf
const float R = 287.052; // specific gas constant R*/M0
const float g = 9.80665; // standard gravity
const float t_grad = 0.0065; // gradient of temperature
- const float t0 = 273.15 + 15; // temperature at 0 altitude
- const float p0 = 101325; // pressure at 0 altitude
+ if(inittemp==0) inittemp=15;
+ if(initpress==0) initpress=101325;
+ float t0 = 273.15 + inittemp; // temperature at 0 altitude
+ float p0 = initpress;// 101700; // pressure at 0 altitude
return t0 / t_grad * (1 - exp((t_grad * R / g) * log(pressure / p0)));
}
diff -r 5760862143d1 -r b7fffbf481e2 MS5607I2C.h
--- a/MS5607I2C.h Tue Jul 03 08:57:57 2012 +0000
+++ b/MS5607I2C.h Wed Dec 25 15:12:21 2019 +0000
@@ -23,12 +23,13 @@
#ifndef MS5607_I2C_H
#define MS5607_I2C_H
+#include "mbed.h"
#include "MS5607Base.h"
class MS5607I2C : public MS5607Base {
public:
MS5607I2C(PinName sda, PinName scl, int csb = 0) : i2c(sda, scl), i2cAddr(csb ? 0xEC : 0xEE) {
- init();
+ // init();
}
private:
diff -r 5760862143d1 -r b7fffbf481e2 MS5607SPI.h
--- a/MS5607SPI.h Tue Jul 03 08:57:57 2012 +0000
+++ b/MS5607SPI.h Wed Dec 25 15:12:21 2019 +0000
@@ -28,7 +28,7 @@
class MS5607SPI : public MS5607Base {
public:
MS5607SPI(PinName mosi, PinName miso, PinName sclk, PinName csb) : spi(mosi, miso, sclk), csb(csb) {
- init();
+ //init();
}
private: