BMP180

Fork of BMP180 by Kevin Gillepsie

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BMP180.h Source File

BMP180.h

00001 #include "mbed.h"
00002 
00003 /***** Definitions *****/
00004 #define I2C_ADDR            (0xEE) // 1110111x
00005 
00006 #define REG_ADDR_RESET      (0xE0)
00007 #define REG_ADDR_ID         (0xD0)
00008 #define REG_ADDR_CTRL       (0xF4)
00009 #define REG_ADDR_DATA       (0xF6)
00010 #define REG_ADDR_AC1        (0xAA)
00011 
00012 #define CTRL_REG_TEMP       (0x2E)
00013 #define CTRL_REG_PRESS_0    (0x34)
00014 #define CTRL_REG_PRESS_1    (0x74)
00015 #define CTRL_REG_PRESS_2    (0xB4)
00016 #define CTRL_REG_PRESS_3    (0xF4)
00017 
00018 
00019 class BMP180
00020 {
00021 
00022 public:
00023 
00024     /**
00025      * @brief   Oversampling ratio.
00026      * @details Dictates how many pressure samples to take. Conversion time varies
00027      *          depending on the number of samples taken. Refer to data sheet
00028      *          for timing specifications.
00029      */
00030     typedef enum {
00031         ULTRA_LOW_POWER       = 0, ///< 1 pressure sample
00032         STANDARD              = 1, ///< 2 pressure samples
00033         HIGH_RESOLUTION       = 2, ///< 4 pressure samples
00034         ULTRA_HIGH_RESOLUTION = 3, ///< 8 pressure samples
00035     } oversampling_t;
00036 
00037     /**
00038      * BMP180 constructor.
00039      *
00040      * @param sda mbed pin to use for SDA line of I2C interface.
00041      * @param scl mbed pin to use for SCL line of I2C interface.
00042      */
00043     BMP180(PinName sda, PinName scl);
00044 
00045     /**
00046      * BMP180 constructor.
00047      *
00048      * @param i2c I2C object to use.
00049      */
00050     BMP180(I2C *i2c);
00051 
00052     /**
00053      * BMP180 destructor.
00054      */
00055     ~BMP180();
00056 
00057     /**
00058      * @brief   Initialize BMP180.
00059      * @details Gets the device ID and saves the calibration values.
00060      * @returns 0 if no errors, -1 if error.
00061      */
00062     int init(void);
00063 
00064     /**
00065      * @brief   Reset BMP180.
00066      * @details Performs a soft reset of the device. Same sequence as power on reset.
00067      * @returns 0 if no errors, -1 if error.
00068      */
00069     int reset(void);
00070 
00071     /**
00072      * @brief   Check ID.
00073      * @details Checks the device ID, should be 0x55 on reset.
00074      * @returns 0 if no errors, -1 if error.
00075      */
00076     int checkId(void);
00077 
00078     /**
00079      * @brief   Start pressure conversion.
00080      * @details Initiates the pressure conversion sequence. Refer to data sheet
00081      *          for timing specifications.
00082      *
00083      * @param   oss Number of samples to take.
00084      * @returns 0 if no errors, -1 if error.
00085      */
00086     int startPressure(BMP180::oversampling_t oss);
00087 
00088     /**
00089      * @brief   Get pressure reading.
00090      * @details Calculates the pressure using the data calibration data and formula.
00091      *          Pressure is reported in Pascals.
00092      * @note    This function should be called after calling startPressure().
00093      *          Refer to the data sheet for the timing requirements. Calling this
00094      *          function too soon can result in oversampling.
00095      *
00096      * @param   pressure Pointer to store pressure reading.
00097      * @returns 0 if no errors, -1 if error.
00098      */
00099     int getPressure(int *pressure);
00100 
00101     /**
00102      * @brief   Start temperature conversion.
00103      * @details Initiates the temperature conversion sequence. Refer to data
00104      *          sheet for timing specifications.
00105      * @returns 0 if no errors, -1 if error.
00106      */
00107     int startTemperature(void);
00108 
00109     /**
00110      * @brief   Get temperature reading.
00111      * @details Calculates the temperature using the data calibration data and formula.
00112      *          Temperature is reported in degrees Celcius.
00113      *
00114      * @note    This function should be called after calling startTemperature().
00115      *          Refer to the data sheet for the timing requirements. Calling this
00116      *          function too soon can result in oversampling.
00117      *
00118      * @param   tempC Pointer to store temperature reading.
00119      * @returns 0 if no errors, -1 if error.
00120      */
00121     int getTemperature(float *tempC);
00122 
00123     /**
00124      * @brief   Get temperature reading.
00125      * @details Calculates the temperature using the data calibration data and formula.
00126      *          Temperature is reported in 1/10ths degrees Celcius.
00127      *
00128      * @note    This function should be called after calling startTemperature().
00129      *          Refer to the data sheet for the timing requirements. Calling this
00130      *          function too soon can result in oversampling.
00131      *
00132      * @param   tempCx10 Pointer to store temperature reading.
00133      * @returns 0 if no errors, -1 if error.
00134      */
00135     int getTemperature(int16_t *tempCx10);
00136 
00137 private:
00138 
00139     typedef union {
00140         uint16_t value[11];
00141         struct {
00142             int16_t ac1;
00143             int16_t ac2;
00144             int16_t ac3;
00145             uint16_t ac4;
00146             uint16_t ac5;
00147             uint16_t ac6;
00148             int16_t b1;
00149             int16_t b2;
00150             int16_t mb;
00151             int16_t mc;
00152             int16_t md;
00153         };
00154     } calibration_t;
00155 
00156     I2C *i2c_;
00157     bool i2c_owner;
00158 
00159     BMP180::calibration_t calib;
00160     int32_t b5;
00161     BMP180::oversampling_t oss_;
00162 };