Correction de la lib car erreur de format dans les calculs

Files at this revision

API Documentation at this revision

Comitter:
bouaziz
Date:
Wed Sep 22 16:14:24 2021 +0000
Parent:
4:ff505486c804
Commit message:
Error corrected in computation un data format.

Changed in this revision

MS5803.cpp Show annotated file Show diff for this revision Revisions of this file
MS5803.h Show annotated file Show diff for this revision Revisions of this file
diff -r ff505486c804 -r 7d839d3899f8 MS5803.cpp
--- a/MS5803.cpp	Sun Mar 20 03:05:18 2016 +0000
+++ b/MS5803.cpp	Wed Sep 22 16:14:24 2021 +0000
@@ -60,7 +60,7 @@
         ms5803_tx_data[0] = ms5803_PROMread + (j<<1);
         if ( i2c.write( device_address,  ms5803_tx_data, 1 ) );
         if ( i2c.read( device_address,  ms5803_rx_data, 2 ) );
-        C[i]   = ms5803_rx_data[1] + (ms5803_rx_data[0]<<8);
+        C[i]   = (unsigned short) ((unsigned int)ms5803_rx_data[1] + (((unsigned int)ms5803_rx_data[0])<<8));
     }
 }
 
@@ -86,7 +86,7 @@
     ms5803_tx_data[0] = ms5803_ADCread;
     if ( i2c.write( device_address,  ms5803_tx_data, 1 ) );
     if ( i2c.read( device_address,  ms5803_rx_data, 3 ) );
-    adc = ms5803_rx_data[2] + (ms5803_rx_data[1]<<8) + (ms5803_rx_data[0]<<16);
+    adc = (unsigned int)ms5803_rx_data[2] + (((unsigned int)ms5803_rx_data[1])<<8) + (((unsigned int)ms5803_rx_data[0])<<16);
     return (adc);
 }
 
@@ -118,13 +118,13 @@
 
     /* calculation according MS5803-01BA data sheet DA5803-01BA_006 */
     dT       = D2 - (C[5]* 256);
-    OFF      = (int64_t)C[2] * (1<<18) + ((int64_t)dT * (int64_t)C[4]) / (1<<5);
-    SENS     = (int64_t)C[1] * (1<<17) + ((int64_t)dT * (int64_t)C[3]) / (1<<6);
-    //OFF      = (int64_t)C[2] * (1<<16) + ((int64_t)dT * (int64_t)C[4]) / (1<<7);
-    //SENS     = (int64_t)C[1] * (1<<15) + ((int64_t)dT * (int64_t)C[3]) / (1<<8);
+ //   OFF      = (int64_t)C[2] * (1<<18) + ((int64_t)dT * (int64_t)C[4]) / (1<<5);
+ //   SENS     = (int64_t)C[1] * (1<<17) + ((int64_t)dT * (int64_t)C[3]) / (1<<6);
+    OFF      = (int64_t)C[2] * (1<<16) + ((int64_t)dT * (int64_t)C[4]) / (1<<7);
+    SENS     = (int64_t)C[1] * (1<<15) + ((int64_t)dT * (int64_t)C[3]) / (1<<8);
 
-    temp     = 2000 + (dT * C[6]) / (1<<23);
+    temp     = 2000 + ((int64_t)dT * C[6]) / (1<<23);
     T_MS5803 = (float) temp / 100.0f;                 // result of temperature in deg C in this var
-    press    = (((int64_t)D1 * SENS) / (1<<21) - OFF) / (1<<15);
-    P_MS5803 = (float) press / 100.0f;                 // result of pressure in mBar in this var
+    press    = ((( (((int64_t)D1)&0xFFFFFFFF) * SENS) / (1<<21) - OFF)) / (1<<15);
+    P_MS5803 = (float)press / 10.;                 // result of pressure in mBar in this var
 }
diff -r ff505486c804 -r 7d839d3899f8 MS5803.h
--- a/MS5803.h	Sun Mar 20 03:05:18 2016 +0000
+++ b/MS5803.h	Wed Sep 22 16:14:24 2021 +0000
@@ -60,7 +60,8 @@
 
 class MS5803{
 private:
-    int D1, D2, Temp, C[8];
+    int D1, D2, Temp;
+    unsigned int C[8];
     float T_MS5803, P_MS5803;
     /* Data buffers */
     char ms5803_rx_data[MS5803_RX_DEPTH];