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
Diff: HP206C.h
- Revision:
- 1:c5247b2ef5af
- Parent:
- 0:817bdb1032c5
- Child:
- 2:8f5aa7475f97
--- a/HP206C.h Tue Jun 25 09:02:19 2019 +0000 +++ b/HP206C.h Tue Jun 25 13:20:39 2019 +0000 @@ -0,0 +1,74 @@ +#ifndef _HP206C +#define _HP206C + +#include "mbed.h" + +#define I2C_BAROMETER_ADDRESS 0x76 << 1 // 0xEC, device adress + +#define HP20X_SOFT_RST 0x06 // for initializing, takes longer than next +#define HP20X_ANA_CAL 0x28 // recalibrate analog internal circuitries, for unstable environment + +#define HP20X_WR_CONVERT_CMD 0x40 + +#define HP20X_READ_PT 0x10 // read pressure and altitude command +#define HP20X_READ_A 0x31 // read altitude command + +#define HP20X_WR_REG_MODE 0xC0 +#define HP20X_RD_REG_MODE 0x80 + +#define HP20X_OK_DEV 0X80 // successfully initialized +#define HP20X_REG_PARA 0X0F // status register + +#define HP20X_CONVERT_OSR4096 0 << 2 +#define HP20X_CONVERT_OSR2048 1 << 2 +#define HP20X_CONVERT_OSR1024 2 << 2 +#define HP20X_CONVERT_OSR512 3 << 2 +#define HP20X_CONVERT_OSR256 4 << 2 +#define HP20X_CONVERT_OSR128 5 << 2 + +#define OSR_CFG HP20X_CONVERT_OSR1024 + +class HP206C +{ +public: + + HP206C(PinName p_sda, PinName p_scl); + /* + float operator()() + { + return performMeasAndgetAltitude(); + } + */ + virtual ~HP206C(); + + void reset(); + + float performMeasAndreadAltitude(); + float readTemperature(); + float readPressure(); + +private: + + I2C i2c; + + float temperature; + float pressure; + float altitude; + bool baro_found; + + unsigned char readRegister(unsigned char reg); + void writeRegister(unsigned char reg, unsigned char data); + void enableCompensation(); + void disableCompensation(); + void softReset(); + void recalibrate(); + uint32_t readData3Bytes(); + uint32_t *readData6Bytes(); + void readTemperatureAndPressureStep1(); + void readTemperatureAndPressureStep2(); + void readAltitude(); + uint8_t getConversionTime(); + +}; + +#endif \ No newline at end of file