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.
BME280.h
00001 #ifndef _BME280_H_ 00002 #define _BME280_H_ 00003 #include "mbed.h" 00004 00005 typedef int32_t BME280_S32_t ; 00006 typedef uint32_t BME280_U32_t ; 00007 typedef long long signed int BME280_S64_t ; 00008 00009 #if 0 00010 #define BME280_U32_t uint32_t 00011 #define BME280_S32_t int32_t 00012 #define BME280_S64_t int64_t 00013 #endif 00014 00015 /** 00016 * BME280 Environmental sensor 00017 * 00018 * @note Note: Interface selection is done by the value of CSB (chip select) 00019 * @note if CSB is pulled-up, I2C interface is active. 00020 * @note if CSB is pulled-down, SPI interface is active. 00021 * @note After CSB has been pulled down once (regardless of whether any clock cycle occurred) 00022 * @note the I2C interface is disabled until the next power-on-reset. 00023 */ 00024 00025 class BME280 00026 { 00027 public: 00028 /** 00029 * BME280 I2C Interface 00030 * 00031 * @param sda SDA pin 00032 * @param scl SCL pin 00033 * @param addr address of the I2C peripheral 00034 */ 00035 BME280(PinName sda, PinName scl, int addr) ; 00036 00037 /** 00038 * BME280 SPI Interface 00039 * 00040 * @param sck SPI SCKL pin 00041 * @param miso SPI Master In Slave Out pin 00042 * @param mosi SPI Master Out Slave In pin 00043 * @param cs SPI Chip Select pin 00044 */ 00045 BME280(PinName sck, PinName miso, PinName mosi, PinName cs) ; 00046 00047 /** 00048 * BME280 destructor 00049 */ 00050 ~BME280() ; 00051 00052 /** 00053 * software reset 00054 * 00055 * @param none 00056 * @returns none 00057 */ 00058 void reset(void) ; 00059 00060 /** 00061 * initialization 00062 * 00063 * @param none 00064 * @reurns none 00065 */ 00066 void init(void) ; 00067 00068 /** 00069 * trigger for one-shot measure 00070 * 00071 * @param none 00072 * @returns none 00073 */ 00074 void trigger(void) ; 00075 00076 /** 00077 * check status register for the device activity 00078 * 00079 * @param none 00080 * @returns uint8_t measuring (0x08) or in NVM udpate (0x01) 00081 */ 00082 uint8_t busy(void) ; 00083 00084 /** 00085 * get device ID 00086 * 00087 * @param none 00088 * @returns uint8_t ID for BME280 0x60 00089 */ 00090 uint8_t getID(void) ; 00091 00092 /** 00093 * get Temperature 00094 * 00095 * @param none 00096 * @returns float temperature in degree Celsious 00097 */ 00098 float getTemperature(void) ; 00099 00100 /** 00101 * get Humidity 00102 * 00103 * @param none 00104 * @returns float humidity in % 00105 */ 00106 float getHumidity(void) ; 00107 00108 /** 00109 * get Pressure 00110 * 00111 * @param none 00112 * @returns float pressure in hPa 00113 */ 00114 float getPressure(void) ; 00115 00116 private: 00117 SPI *m_spi ; 00118 I2C *m_i2c ; 00119 DigitalOut *m_cs ; 00120 int m_addr ; 00121 BME280_S32_t t_fine ; 00122 00123 uint16_t dig_T1 ; 00124 int16_t dig_T2 ; 00125 int16_t dig_T3 ; 00126 uint16_t dig_P1 ; 00127 int16_t dig_P2 ; 00128 int16_t dig_P3 ; 00129 int16_t dig_P4 ; 00130 int16_t dig_P5 ; 00131 int16_t dig_P6 ; 00132 int16_t dig_P7 ; 00133 int16_t dig_P8 ; 00134 int16_t dig_P9 ; 00135 uint8_t dig_H1 ; 00136 int16_t dig_H2 ; 00137 uint8_t dig_H3 ; 00138 int16_t dig_H4 ; 00139 int16_t dig_H5 ; 00140 int8_t dig_H6 ; 00141 00142 void i2c_readRegs(int addr, uint8_t *data, int len) ; 00143 void i2c_writeRegs(uint8_t *data, int len) ; 00144 void spi_readRegs(int addr, uint8_t *data, int len) ; 00145 void spi_writeRegs(uint8_t *data, int len) ; 00146 void readRegs(int addr, uint8_t *data, int len) ; 00147 void writeRegs(uint8_t *data, int len) ; 00148 } ; 00149 #endif /* _BME280_H_ */
Generated on Sat Jul 30 2022 14:00:05 by
1.7.2