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
Diff: keller_pressure.cpp
- Revision:
- 1:805ee7853062
- Parent:
- 0:fc5c10fc5a05
- Child:
- 2:d6c82c96dae7
- Child:
- 3:1a0add40e308
diff -r fc5c10fc5a05 -r 805ee7853062 keller_pressure.cpp --- 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 }