Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TestBenchSerenity-proto_F429ZI TestBenchFlow HSPFLOW1 TestBenchFlow1 ... more
Revision 1:805ee7853062, committed 2017-05-10
- Comitter:
- dmwahl
- Date:
- Wed May 10 16:57:58 2017 +0000
- Parent:
- 0:fc5c10fc5a05
- Child:
- 2:d6c82c96dae7
- Child:
- 3:1a0add40e308
- Commit message:
- All functions working
Changed in this revision
| keller_pressure.cpp | Show annotated file Show diff for this revision Revisions of this file |
| keller_pressure.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/keller_pressure.cpp Tue May 09 21:43:26 2017 +0000
+++ b/keller_pressure.cpp Wed May 10 16:57:58 2017 +0000
@@ -44,11 +44,11 @@
status = data[0];
pressure = (data[1] << 8) | data[2];
temperature = (data[3] << 8) | data[4];
-
+
pressureBAR = ((pressure - 16384)*(pmax-pmin))/32768+pmin;
pressurePSI = pressureBAR*14.5038;
pressureKPA = pressureBAR*100;
-
+
temperatureC = (temperature - 384)*0.003125-50;
temperatureF = (temperatureC*1.8+32);
result = true;
@@ -60,32 +60,47 @@
void KELLER_PRESSURE::readUserInfo()
{
char data[3];
- //const uint8_t i = NELEMS(data);
- // _read_multibyte(char regAddress, char* data, char count)
+
_read_multibyte(KELLER_PRESSURE_CUST_ID0, data, 3);
Cust_ID0 = (data[1] << 8) | data[2];
_read_multibyte(KELLER_PRESSURE_CUST_ID1, data, 3);
Cust_ID1 = (data[1] << 8) | data[2];
+ // Scaling0 contains date/mode information
_read_multibyte(KELLER_PRESSURE_SCALING0, data, 3);
Scaling0 = (data[1] << 8) | data[2];
+ union {
+ char c[4];
+ float f;
+ } u;
+
+ //Scaling1 and Scaling2 contain lower pressure limit
_read_multibyte(KELLER_PRESSURE_SCALING1, data, 3);
Scaling1 = (data[1] << 8) | data[2];
+ u.c[3] = data[1];
+ u.c[2] = data[2];
_read_multibyte(KELLER_PRESSURE_SCALING2, data, 3);
Scaling2 = (data[1] << 8) | data[2];
+ u.c[1] = data[1];
+ u.c[0] = data[2];
+ pmin = u.f;
+ //Scaling3 and Scaling4 contain upper pressure limit
_read_multibyte(KELLER_PRESSURE_SCALING3, data, 3);
Scaling3 = (data[1] << 8) | data[2];
+ u.c[3] = data[1];
+ u.c[2] = data[2];
_read_multibyte(KELLER_PRESSURE_SCALING4, data, 3);
Scaling4 = (data[1] << 8) | data[2];
+ u.c[1] = data[1];
+ u.c[0] = data[2];
+ pmax = u.f;
- pmin = ((Scaling1 << 16) | Scaling2)/(0xBF800000)*-1.0;
- pmax = ((Scaling3 << 16) | Scaling4)/(1092616192.0)*10.0;
-
+ // Read out date of manufacture information and sensor mode
year = ((Scaling0 & KELLER_PRESSURE_SCALING0_YEAR_MASK) >> 11) + 2010;
month = (Scaling0 & KELLER_PRESSURE_SCALING0_MONTH_MASK) >> 7;
day = (Scaling0 & KELLER_PRESSURE_SCALING0_DAY_MASK) >> 2;
@@ -136,8 +151,7 @@
i2c.stop();
//wait_us(500);
- while (getStatus() != 0x40)
- {
+ while (getStatus() != 0x40) {
wait_us(10); // wait until the status bit indicates conversion has completed
}
--- a/keller_pressure.h Tue May 09 21:43:26 2017 +0000
+++ b/keller_pressure.h Wed May 10 16:57:58 2017 +0000
@@ -6,8 +6,6 @@
#define I2C_READ 1
#define I2C_WRITE 0
-#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
-
#define KELLER_PRESSURE_I2C_CLK_SPD 400000L
#define KELLER_PRESSURE_REQUEST_MEASUREMENT 0xAC
@@ -19,12 +17,10 @@
#define KELLER_PRESSURE_SCALING3 0x15 // Pmax [bar] MSWord (Pmax [bar] als 32bit float)
#define KELLER_PRESSURE_SCALING4 0x16 // Pmax [bar] LSWord (Pmax [bar] als 32bit float)
-#define KELLER_PRESSURE_SCALING0_YEAR_MASK 0b1111100000000000
-#define KELLER_PRESSURE_SCALING0_MONTH_MASK 0b0000011110000000
-#define KELLER_PRESSURE_SCALING0_DAY_MASK 0b0000000001111100
-#define KELLER_PRESSURE_SCALING0_MODE_MASK 0b0000000000000011
-
-
+#define KELLER_PRESSURE_SCALING0_YEAR_MASK 0xF800
+#define KELLER_PRESSURE_SCALING0_MONTH_MASK 0x0780
+#define KELLER_PRESSURE_SCALING0_DAY_MASK 0x007C
+#define KELLER_PRESSURE_SCALING0_MODE_MASK 0x0003
class KELLER_PRESSURE
{
@@ -49,7 +45,7 @@
uint8_t month, day, mode;
uint16_t status, pressure, temperature; // raw readings
- double pmin, pmax; // Min, max pressures (bar) read from device
+ float pmin, pmax; // Min, max pressures (bar) read from device
// Pressures are absolute
double pressureBAR, pressurePSI, pressureKPA, temperatureC, temperatureF;