MEMS pressure sensor by STMicroelectronics. FIFO Hardware digital filter as default.

Dependents:   WeatherSensor-Joe PAG-CourseWork-NicksEdits SOFT253_Assignment SOFT253_Assignment_V2 ... more

Fork of LPS25H by Kenji Arai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LPS25H.h Source File

LPS25H.h

00001 /*
00002  * mbed library program
00003  *  LPS25H MEMS pressure sensor: 260-1260 hPa absolute digital output barometer
00004  *   made by STMicroelectronics
00005  *   http://www.st-japan.co.jp/web/catalog/sense_power/FM89/SC1316/PF255230
00006  *
00007  * Copyright (c) 2015 Kenji Arai / JH1PJL
00008  *  http://www.page.sannet.ne.jp/kenjia/index.html
00009  *  http://mbed.org/users/kenjiArai/
00010  *      Created: Feburary  21st, 2015
00011  *      Revised: Feburary  22nd, 2015
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
00014  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00015  * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 /*
00020  *---------------- REFERENCE ----------------------------------------------------------------------
00021  * Original Information
00022  *  http://www.st-japan.co.jp/web/jp/catalog/sense_power/FM89/SC1316/PF255230
00023  * AN4450 Application Note (as follows)
00024  *  http://www.st.com/st-web-ui/static/active/jp/
00025  *         resource/technical/document/application_note/DM00108837.pdf
00026  * Device kit
00027  *  http://akizukidenshi.com/catalog/g/gK-08338/
00028  */
00029 
00030 #ifndef LPS25H_H
00031 #define LPS25H_H
00032 
00033 #include "mbed.h"
00034 
00035 //  LPS25H Address
00036 //  7bit address = 0b101110x(0x5c or 0x5d depends on SA0/SDO)
00037 #define LPS25H_G_CHIP_ADDR  (0x5c << 1)    // SA0(=SDO pin) = Ground
00038 #define LPS25H_V_CHIP_ADDR  (0x5d << 1)    // SA0(=SDO pin) = Vdd
00039 
00040 // MODE Selection
00041 #define FIFO_HW_FILTER          1
00042 #define FIFO_BYPASS             0
00043 
00044 //   LPS25H ID
00045 #define I_AM_LPS25H            0xbd
00046 
00047 //  Register's definition
00048 #define LPS25H_WHO_AM_I        0x0f
00049 #define LPS25H_RES_CONF        0x10
00050 
00051 #define LPS25H_CTRL_REG1       0x20
00052 #define LPS25H_CTRL_REG2       0x21
00053 #define LPS25H_CTRL_REG3       0x22
00054 #define LPS25H_CTRL_REG4       0x23
00055 
00056 #define LPS25H_STATUS_REG      0x27
00057 #define LPS25H_PRESS_POUT_XL   0x28
00058 #define LPS25H_PRESS_OUT_L     0x29
00059 #define LPS25H_PRESS_OUT_H     0x2a
00060 #define LPS25H_TEMP_OUT_L      0x2b
00061 #define LPS25H_TEMP_OUT_H      0x2c
00062 
00063 #define LPS25H_FIFO_CTRL       0x2e
00064 #define LPS25H_FIFO_STATUS     0x2e
00065 
00066 // Control Reg.
00067 #define PD              (0UL << 7)
00068 #define ACTIVE          (1UL << 7)
00069 #define ODR_ONESHOT     (0UL << 4)
00070 #define ODR_1HZ         (1UL << 4)
00071 #define ODR_7HZ         (1UL << 4)
00072 #define ODR_12R5HZ      (2UL << 4)
00073 #define ODR_25HZ        (3UL << 4)
00074 #define BDU_SET         (1UL << 2)
00075 #define CR_STD_SET      (ACTIVE + ODR_7HZ + BDU_SET)
00076 
00077 // FIFO Control
00078 #define FIFO_MEAN_MODE         0xc0
00079 #define FIFO_SAMPLE_2          0x01
00080 #define FIFO_SAMPLE_4          0x03
00081 #define FIFO_SAMPLE_8          0x07
00082 #define FIFO_SAMPLE_16         0x0f
00083 #define FIFO_SAMPLE_32         0x1f
00084 
00085 /** Interface for STMicronics MEMS pressure sensor
00086  *      Chip: LPS25H
00087  *
00088  * @code
00089  * #include "mbed.h"
00090  * #include "LPS25H.h"
00091  *
00092  * // I2C Communication
00093  * LPS25H baro(p_sda, p_scl, LPS25H_G_CHIP_ADDR);
00094  * // If you connected I2C line not only this device but also other devices,
00095  * //     you need to declare following method.
00096  * I2C i2c(dp5,dp27);              // SDA, SCL
00097  * LPS25H baro(i2c, LPS25H_G_CHIP_ADDR);
00098  *
00099  * int main() {
00100  *   while( trure){
00101  *      baro.get();
00102  *      printf("Presere: 0x%6.1f, Temperature: 0x%+4.1f\r\n", baro.pressue(), baro.temperature());
00103  *      wait(1.0);
00104  *   }
00105  * }
00106  * @endcode
00107  */
00108 
00109 class LPS25H
00110 {
00111 public:
00112     /** Configure data pin
00113       * @param data SDA and SCL pins
00114       * @param device address LPS25H(SA0=0 or 1), LPS25H_G_CHIP_ADDR or LPS25H_V_CHIP_ADDR
00115       * @param Operation mode FIFO_HW_FILTER(default) or FIFO_BYPASS (Option parameter)
00116       */
00117     LPS25H(PinName p_sda, PinName p_scl, uint8_t addr);
00118     LPS25H(PinName p_sda, PinName p_scl, uint8_t addr, uint8_t mode);
00119 
00120     /** Configure data pin (with other devices on I2C line)
00121       * @param I2C previous definition
00122       * @param device address LPS25H(SA0=0 or 1), LPS25H_G_CHIP_ADDR or LPS25H_V_CHIP_ADDR
00123       * @param Operation mode FIFO_HW_FILTER(default) or FIFO_BYPASS (Option parameter)
00124       */
00125     LPS25H(I2C& p_i2c, uint8_t addr);
00126     LPS25H(I2C& p_i2c, uint8_t addr, uint8_t mode);
00127 
00128     /** Start convertion & data save
00129       * @param none
00130       * @return none
00131       */
00132     void get(void);
00133 
00134     /** Read pressure data
00135       * @param none
00136       * @return humidity
00137       */
00138     float pressure(void);
00139 
00140     /** Read temperature data
00141       * @param none
00142       * @return temperature
00143       */
00144     float temperature(void);
00145 
00146     /** Read a ID number
00147       * @param none
00148       * @return if STM MEMS LPS25H, it should be I_AM_ LPS25H
00149       */
00150     uint8_t read_id(void);
00151 
00152     /** Read Data Ready flag
00153       * @param none
00154       * @return 1 = Ready
00155       */
00156     uint8_t data_ready(void);
00157 
00158     /** Set I2C clock frequency
00159       * @param freq.
00160       * @return none
00161       */
00162     void frequency(int hz);
00163 
00164     /** Read register (general purpose)
00165       * @param register's address
00166       * @return register data
00167       */
00168     uint8_t read_reg(uint8_t addr);
00169 
00170     /** Write register (general purpose)
00171       * @param register's address
00172       * @param data
00173       * @return none
00174       */
00175     void write_reg(uint8_t addr, uint8_t data);
00176 
00177 protected:
00178     I2C _i2c;
00179 
00180     void init(void);
00181 
00182 private:
00183     char dt[6];            // working buffer
00184     uint8_t LPS25H_addr;   // Sensor address
00185     uint8_t LPS25H_id;     // ID
00186     uint8_t LPS25H_ready;  // Device is on I2C line = 1, not = 0
00187     uint8_t LPS25H_mode;   // Operation mode
00188     uint32_t press;        // pressure raw data
00189     int16_t temp;          // temperature raw data
00190 };
00191 
00192 #endif      // LPS25H_H