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: Grove-Barometric_Pressure_Sensor_Example
HP206C.h@3:dd1c93488020, 2019-06-25 (annotated)
- Committer:
- pmic
- Date:
- Tue Jun 25 14:03:58 2019 +0000
- Revision:
- 3:dd1c93488020
- Parent:
- 2:8f5aa7475f97
- Child:
- 4:a2b79f08ad14
enhance stuff
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 1:c5247b2ef5af | 1 | #ifndef _HP206C |
pmic | 1:c5247b2ef5af | 2 | #define _HP206C |
pmic | 1:c5247b2ef5af | 3 | |
pmic | 1:c5247b2ef5af | 4 | #include "mbed.h" |
pmic | 1:c5247b2ef5af | 5 | |
pmic | 1:c5247b2ef5af | 6 | #define I2C_BAROMETER_ADDRESS 0x76 << 1 // 0xEC, device adress |
pmic | 1:c5247b2ef5af | 7 | |
pmic | 1:c5247b2ef5af | 8 | #define HP20X_SOFT_RST 0x06 // for initializing, takes longer than next |
pmic | 1:c5247b2ef5af | 9 | #define HP20X_ANA_CAL 0x28 // recalibrate analog internal circuitries, for unstable environment |
pmic | 1:c5247b2ef5af | 10 | |
pmic | 1:c5247b2ef5af | 11 | #define HP20X_WR_CONVERT_CMD 0x40 |
pmic | 1:c5247b2ef5af | 12 | |
pmic | 1:c5247b2ef5af | 13 | #define HP20X_READ_PT 0x10 // read pressure and altitude command |
pmic | 1:c5247b2ef5af | 14 | #define HP20X_READ_A 0x31 // read altitude command |
pmic | 1:c5247b2ef5af | 15 | |
pmic | 1:c5247b2ef5af | 16 | #define HP20X_WR_REG_MODE 0xC0 |
pmic | 1:c5247b2ef5af | 17 | #define HP20X_RD_REG_MODE 0x80 |
pmic | 1:c5247b2ef5af | 18 | |
pmic | 1:c5247b2ef5af | 19 | #define HP20X_OK_DEV 0X80 // successfully initialized |
pmic | 1:c5247b2ef5af | 20 | #define HP20X_REG_PARA 0X0F // status register |
pmic | 1:c5247b2ef5af | 21 | |
pmic | 1:c5247b2ef5af | 22 | #define HP20X_CONVERT_OSR4096 0 << 2 |
pmic | 1:c5247b2ef5af | 23 | #define HP20X_CONVERT_OSR2048 1 << 2 |
pmic | 1:c5247b2ef5af | 24 | #define HP20X_CONVERT_OSR1024 2 << 2 |
pmic | 1:c5247b2ef5af | 25 | #define HP20X_CONVERT_OSR512 3 << 2 |
pmic | 1:c5247b2ef5af | 26 | #define HP20X_CONVERT_OSR256 4 << 2 |
pmic | 1:c5247b2ef5af | 27 | #define HP20X_CONVERT_OSR128 5 << 2 |
pmic | 1:c5247b2ef5af | 28 | |
pmic | 3:dd1c93488020 | 29 | #define OSR_CFG HP20X_CONVERT_OSR4096 |
pmic | 1:c5247b2ef5af | 30 | |
pmic | 1:c5247b2ef5af | 31 | class HP206C |
pmic | 1:c5247b2ef5af | 32 | { |
pmic | 1:c5247b2ef5af | 33 | public: |
pmic | 1:c5247b2ef5af | 34 | |
pmic | 1:c5247b2ef5af | 35 | HP206C(PinName p_sda, PinName p_scl); |
pmic | 3:dd1c93488020 | 36 | |
pmic | 3:dd1c93488020 | 37 | float operator()() { |
pmic | 3:dd1c93488020 | 38 | return readAltitude(); |
pmic | 1:c5247b2ef5af | 39 | } |
pmic | 3:dd1c93488020 | 40 | |
pmic | 1:c5247b2ef5af | 41 | virtual ~HP206C(); |
pmic | 1:c5247b2ef5af | 42 | |
pmic | 1:c5247b2ef5af | 43 | void reset(); |
pmic | 3:dd1c93488020 | 44 | float readAltitude(); |
pmic | 1:c5247b2ef5af | 45 | |
pmic | 1:c5247b2ef5af | 46 | private: |
pmic | 1:c5247b2ef5af | 47 | |
pmic | 1:c5247b2ef5af | 48 | I2C i2c; |
pmic | 1:c5247b2ef5af | 49 | |
pmic | 3:dd1c93488020 | 50 | float altitude; |
pmic | 3:dd1c93488020 | 51 | bool baro_found; |
pmic | 3:dd1c93488020 | 52 | uint8_t OSR_ConvertTime; |
pmic | 1:c5247b2ef5af | 53 | |
pmic | 1:c5247b2ef5af | 54 | unsigned char readRegister(unsigned char reg); |
pmic | 1:c5247b2ef5af | 55 | void writeRegister(unsigned char reg, unsigned char data); |
pmic | 1:c5247b2ef5af | 56 | void enableCompensation(); |
pmic | 1:c5247b2ef5af | 57 | void disableCompensation(); |
pmic | 1:c5247b2ef5af | 58 | void softReset(); |
pmic | 1:c5247b2ef5af | 59 | void recalibrate(); |
pmic | 1:c5247b2ef5af | 60 | uint32_t readData3Bytes(); |
pmic | 3:dd1c93488020 | 61 | void readTemperatureAndPressure(); |
pmic | 3:dd1c93488020 | 62 | void updateAltitude(); |
pmic | 3:dd1c93488020 | 63 | void setConversionTime(); |
pmic | 1:c5247b2ef5af | 64 | |
pmic | 1:c5247b2ef5af | 65 | }; |
pmic | 1:c5247b2ef5af | 66 | |
pmic | 1:c5247b2ef5af | 67 | #endif |