Library to read from Keller Druck I2C Pressure sensors. Inputs are I2C object and address.
Dependents: TestBenchSerenity-proto_F429ZI TestBenchFlow HSPFLOW1 TestBenchFlow1 ... more
keller_pressure.h@3:1a0add40e308, 2017-05-23 (annotated)
- Committer:
- dmwahl
- Date:
- Tue May 23 17:29:25 2017 +0000
- Revision:
- 3:1a0add40e308
- Parent:
- 1:805ee7853062
- Child:
- 6:deb4008b136e
Added error detection and simplified i2c commands
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmwahl | 0:fc5c10fc5a05 | 1 | #ifndef KELLER_PRESSURE_H |
dmwahl | 0:fc5c10fc5a05 | 2 | #define KELLER_PRESSURE_H |
dmwahl | 0:fc5c10fc5a05 | 3 | |
dmwahl | 0:fc5c10fc5a05 | 4 | #include "mbed.h" |
dmwahl | 0:fc5c10fc5a05 | 5 | |
dmwahl | 0:fc5c10fc5a05 | 6 | #define I2C_READ 1 |
dmwahl | 0:fc5c10fc5a05 | 7 | #define I2C_WRITE 0 |
dmwahl | 0:fc5c10fc5a05 | 8 | |
dmwahl | 0:fc5c10fc5a05 | 9 | #define KELLER_PRESSURE_I2C_CLK_SPD 400000L |
dmwahl | 0:fc5c10fc5a05 | 10 | #define KELLER_PRESSURE_REQUEST_MEASUREMENT 0xAC |
dmwahl | 3:1a0add40e308 | 11 | #define KELLER_PRESSURE_MEASUREMENT_DONE 0x40 |
dmwahl | 0:fc5c10fc5a05 | 12 | |
dmwahl | 0:fc5c10fc5a05 | 13 | #define KELLER_PRESSURE_CUST_ID0 0x00 // for DB access |
dmwahl | 0:fc5c10fc5a05 | 14 | #define KELLER_PRESSURE_CUST_ID1 0x01 // for DB access |
dmwahl | 0:fc5c10fc5a05 | 15 | #define KELLER_PRESSURE_SCALING0 0x12 // Year [0..31]+2010 Bit11..15 | Month [0..15] Bit7..10| Day [0..31] Bit2..6| P-Mode[0..3] Bit0..1 (Y:5bit|M:4bit|D:5bit|P:2bit) |
dmwahl | 0:fc5c10fc5a05 | 16 | #define KELLER_PRESSURE_SCALING1 0x13 // Pmin [bar] MSWord (Pmin [bar] als 32bit float) |
dmwahl | 0:fc5c10fc5a05 | 17 | #define KELLER_PRESSURE_SCALING2 0x14 // Pmin [bar] LSWord (Pmin [bar] als 32bit float) |
dmwahl | 0:fc5c10fc5a05 | 18 | #define KELLER_PRESSURE_SCALING3 0x15 // Pmax [bar] MSWord (Pmax [bar] als 32bit float) |
dmwahl | 0:fc5c10fc5a05 | 19 | #define KELLER_PRESSURE_SCALING4 0x16 // Pmax [bar] LSWord (Pmax [bar] als 32bit float) |
dmwahl | 0:fc5c10fc5a05 | 20 | |
dmwahl | 1:805ee7853062 | 21 | #define KELLER_PRESSURE_SCALING0_YEAR_MASK 0xF800 |
dmwahl | 1:805ee7853062 | 22 | #define KELLER_PRESSURE_SCALING0_MONTH_MASK 0x0780 |
dmwahl | 1:805ee7853062 | 23 | #define KELLER_PRESSURE_SCALING0_DAY_MASK 0x007C |
dmwahl | 1:805ee7853062 | 24 | #define KELLER_PRESSURE_SCALING0_MODE_MASK 0x0003 |
dmwahl | 0:fc5c10fc5a05 | 25 | |
dmwahl | 0:fc5c10fc5a05 | 26 | class KELLER_PRESSURE |
dmwahl | 0:fc5c10fc5a05 | 27 | { |
dmwahl | 0:fc5c10fc5a05 | 28 | protected: |
dmwahl | 0:fc5c10fc5a05 | 29 | I2C &i2c; |
dmwahl | 0:fc5c10fc5a05 | 30 | uint8_t mi2cAddress; |
dmwahl | 0:fc5c10fc5a05 | 31 | |
dmwahl | 3:1a0add40e308 | 32 | char _write(char regAddress, char data); |
dmwahl | 3:1a0add40e308 | 33 | char _read_multibyte(char regAddress, char* data, char count); |
dmwahl | 0:fc5c10fc5a05 | 34 | |
dmwahl | 0:fc5c10fc5a05 | 35 | |
dmwahl | 0:fc5c10fc5a05 | 36 | public: |
dmwahl | 0:fc5c10fc5a05 | 37 | KELLER_PRESSURE(I2C &i2c, int addr); |
dmwahl | 0:fc5c10fc5a05 | 38 | ~KELLER_PRESSURE(); |
dmwahl | 0:fc5c10fc5a05 | 39 | char getStatus(); |
dmwahl | 0:fc5c10fc5a05 | 40 | |
dmwahl | 0:fc5c10fc5a05 | 41 | uint16_t Cust_ID0, Cust_ID1, Scaling0, Scaling1, Scaling2, Scaling3, Scaling4; |
dmwahl | 0:fc5c10fc5a05 | 42 | |
dmwahl | 0:fc5c10fc5a05 | 43 | // Date of manufacture info |
dmwahl | 0:fc5c10fc5a05 | 44 | uint16_t year; |
dmwahl | 0:fc5c10fc5a05 | 45 | uint8_t month, day, mode; |
dmwahl | 0:fc5c10fc5a05 | 46 | |
dmwahl | 0:fc5c10fc5a05 | 47 | uint16_t status, pressure, temperature; // raw readings |
dmwahl | 1:805ee7853062 | 48 | float pmin, pmax; // Min, max pressures (bar) read from device |
dmwahl | 0:fc5c10fc5a05 | 49 | |
dmwahl | 0:fc5c10fc5a05 | 50 | // Pressures are absolute |
dmwahl | 0:fc5c10fc5a05 | 51 | double pressureBAR, pressurePSI, pressureKPA, temperatureC, temperatureF; |
dmwahl | 0:fc5c10fc5a05 | 52 | |
dmwahl | 3:1a0add40e308 | 53 | char readPT(); // return 0 if good reading, 1 if error |
dmwahl | 0:fc5c10fc5a05 | 54 | bool isAvailable(); |
dmwahl | 3:1a0add40e308 | 55 | char readUserInfo(); |
dmwahl | 0:fc5c10fc5a05 | 56 | }; |
dmwahl | 0:fc5c10fc5a05 | 57 | |
dmwahl | 0:fc5c10fc5a05 | 58 | #endif |