My trial of BME280 library, tested with Adafruit BME280 module
BME280.h
- Committer:
- Rhyme
- Date:
- 2017-05-09
- Revision:
- 0:5ace1cc7a9f2
- Child:
- 1:7b525853bad0
File content as of revision 0:5ace1cc7a9f2:
#ifndef _BME280_H_
#define _BME280_H_
#include "mbed.h"
#define BME280_U32_t uint32_t
#define BME280_S32_t int32_t
#define BME280_S64_t int64_t
/**
* BME280 Environmental sensor
*
* Note: Interface selection is done by the value of CSB (chip select)
* if CSB is pulled-up, I2C interface is active.
* if CSB is pulled-down, SPI interface is active.
* After CSB has been pulled down once (regardless of whether any clock cycle occurred)
* the I2C interface is disabled until the next power-on-reset.
*/
class BME280
{
public:
/**
* BME280 I2C Interface
*
* @param sda SDA pin
* @param scl SCL pin
* @param addr address of the I2C peripheral
*/
BME280(PinName sda, PinName scl, int addr) ;
/**
* BME280 SPI Interface
*
* @param sck SPI SCKL pin
* @param miso SPI Master In Slave Out pin
* @param mosi SPI Master Out Slave In pin
* @param cs SPI Chip Select pin
*/
BME280(PinName sck, PinName miso, PinName mosi, PinName cs) ;
~BME280() ;
void reset(void) ;
void init(void) ;
void trigger(void) ; /* forced mode */
uint8_t busy(void) ;
uint8_t getID(void) ;
void readData(uint8_t data[]) ;
float getTemperature(uint8_t data[]) ;
float getHumidity(uint8_t data[]) ;
float getPressure(uint8_t data[]) ;
private:
SPI *m_spi ;
I2C *m_i2c ;
DigitalOut *m_cs ;
int m_addr ;
BME280_S32_t t_fine ;
uint16_t dig_T1, dig_T2, dig_T3 ;
uint16_t dig_P1, dig_P2, dig_P3 ;
uint16_t dig_P4, dig_P5, dig_P6 ;
uint16_t dig_P7, dig_P8, dig_P9 ;
uint16_t dig_H1, dig_H2, dig_H3 ;
uint16_t dig_H4, dig_H5, dig_H6 ;
void i2c_readRegs(int addr, uint8_t *data, int len) ;
void i2c_writeRegs(uint8_t *data, int len) ;
void spi_readRegs(int addr, uint8_t *data, int len) ;
void spi_writeRegs(uint8_t *data, int len) ;
void readRegs(int addr, uint8_t *data, int len) ;
void writeRegs(uint8_t *data, int len) ;
} ;
#endif /* _BME280_H_ */