BM1383AGLV sensor library
Dependents: simple-sensor-client rohm-SensorShield-example
BM1383AGLV.h@1:997a1eb76a4f, 2020-11-20 (annotated)
- Committer:
- MACRUM
- Date:
- Fri Nov 20 14:55:11 2020 +0000
- Revision:
- 1:997a1eb76a4f
- Parent:
- 0:d505f3c67a62
Add ready-status check
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:d505f3c67a62 | 1 | /* Copyright (c) 2015 ARM Ltd., MIT License |
MACRUM | 0:d505f3c67a62 | 2 | * |
MACRUM | 0:d505f3c67a62 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
MACRUM | 0:d505f3c67a62 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
MACRUM | 0:d505f3c67a62 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
MACRUM | 0:d505f3c67a62 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
MACRUM | 0:d505f3c67a62 | 7 | * Software is furnished to do so, subject to the following conditions: |
MACRUM | 0:d505f3c67a62 | 8 | * |
MACRUM | 0:d505f3c67a62 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
MACRUM | 0:d505f3c67a62 | 10 | * substantial portions of the Software. |
MACRUM | 0:d505f3c67a62 | 11 | * |
MACRUM | 0:d505f3c67a62 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
MACRUM | 0:d505f3c67a62 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
MACRUM | 0:d505f3c67a62 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
MACRUM | 0:d505f3c67a62 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MACRUM | 0:d505f3c67a62 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
MACRUM | 0:d505f3c67a62 | 17 | * |
MACRUM | 0:d505f3c67a62 | 18 | * |
MACRUM | 0:d505f3c67a62 | 19 | * BM1383AGLV Pressure sensor library |
MACRUM | 0:d505f3c67a62 | 20 | * |
MACRUM | 0:d505f3c67a62 | 21 | * @author Toyomasa Watarai |
MACRUM | 0:d505f3c67a62 | 22 | * @version 1.0 |
MACRUM | 0:d505f3c67a62 | 23 | * @date 30-December-2015 |
MACRUM | 0:d505f3c67a62 | 24 | * |
MACRUM | 0:d505f3c67a62 | 25 | * Library for "BM1383AGLV Pressure sensor library" |
MACRUM | 0:d505f3c67a62 | 26 | * http://www.rohm.com/web/eu/news-detail?news-title=2014-12-11_ad_pressure&defaultGroupId=false |
MACRUM | 0:d505f3c67a62 | 27 | * |
MACRUM | 0:d505f3c67a62 | 28 | */ |
MACRUM | 0:d505f3c67a62 | 29 | |
MACRUM | 0:d505f3c67a62 | 30 | #ifndef BM1383AGLV_H |
MACRUM | 0:d505f3c67a62 | 31 | #define BM1383AGLV_H |
MACRUM | 0:d505f3c67a62 | 32 | |
MACRUM | 0:d505f3c67a62 | 33 | #include "mbed.h" |
MACRUM | 0:d505f3c67a62 | 34 | |
MACRUM | 0:d505f3c67a62 | 35 | #define BM1383AGLV_DEFAULT_SLAVE_ADDRESS (0x5D << 1) |
MACRUM | 0:d505f3c67a62 | 36 | #define BM1383AGLV_ID1_VAL (0xE0) |
MACRUM | 0:d505f3c67a62 | 37 | #define BM1383AGLV_ID2_VAL (0x32) |
MACRUM | 0:d505f3c67a62 | 38 | #define BM1383AGLV_ID1 (0x0F) |
MACRUM | 0:d505f3c67a62 | 39 | #define BM1383AGLV_ID2 (0x10) |
MACRUM | 0:d505f3c67a62 | 40 | #define BM1383AGLV_POWER_DOWN (0x12) |
MACRUM | 0:d505f3c67a62 | 41 | #define BM1383AGLV_RESET (0x13) |
MACRUM | 0:d505f3c67a62 | 42 | #define BM1383AGLV_MODE_CONTROL (0x14) |
MACRUM | 0:d505f3c67a62 | 43 | #define BM1383AGLV_STATUS (0x19) |
MACRUM | 0:d505f3c67a62 | 44 | #define BM1383AGLV_PRESSURE_MSB (0x1A) |
MACRUM | 0:d505f3c67a62 | 45 | #define BM1383AGLV_PRESSURE_LSB (0x1B) |
MACRUM | 0:d505f3c67a62 | 46 | #define BM1383AGLV_PRESSURE_XLSB (0x1C) |
MACRUM | 0:d505f3c67a62 | 47 | #define BM1383AGLV_TEMPERATURE_MSB (0x1D) |
MACRUM | 0:d505f3c67a62 | 48 | #define BM1383AGLV_TEMPERATURE_LSB (0x1E) |
MACRUM | 0:d505f3c67a62 | 49 | |
MACRUM | 1:997a1eb76a4f | 50 | #define BM1383AGLV_WAIT_READY_STATUS 0 |
MACRUM | 1:997a1eb76a4f | 51 | |
MACRUM | 0:d505f3c67a62 | 52 | #ifdef _DEBUG |
MACRUM | 0:d505f3c67a62 | 53 | extern Serial pc; |
MACRUM | 0:d505f3c67a62 | 54 | #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) |
MACRUM | 0:d505f3c67a62 | 55 | #else |
MACRUM | 0:d505f3c67a62 | 56 | #define DEBUG_PRINT(...) |
MACRUM | 0:d505f3c67a62 | 57 | #endif |
MACRUM | 0:d505f3c67a62 | 58 | |
MACRUM | 0:d505f3c67a62 | 59 | /** |
MACRUM | 0:d505f3c67a62 | 60 | * BM1383AGLV pressure sensor example |
MACRUM | 0:d505f3c67a62 | 61 | * |
MACRUM | 0:d505f3c67a62 | 62 | * @code |
MACRUM | 0:d505f3c67a62 | 63 | * BM1383AGLV sensor(I2C_SDA, I2C_SCL); |
MACRUM | 0:d505f3c67a62 | 64 | * Serial pc(USBTX, USBRX); |
MACRUM | 0:d505f3c67a62 | 65 | * |
MACRUM | 0:d505f3c67a62 | 66 | * int main() { |
MACRUM | 0:d505f3c67a62 | 67 | * pc.printf("\nBM1383AGLV Pressure sensor library test program.\n"); |
MACRUM | 0:d505f3c67a62 | 68 | * |
MACRUM | 0:d505f3c67a62 | 69 | * while(1) { |
MACRUM | 0:d505f3c67a62 | 70 | * pc.printf("pressure=%7.2f, temperature=%5.3f\n", sensor.getPressure(), sensor.getTemperature()); |
MACRUM | 0:d505f3c67a62 | 71 | * wait(0.5); |
MACRUM | 0:d505f3c67a62 | 72 | * } |
MACRUM | 0:d505f3c67a62 | 73 | * } |
MACRUM | 0:d505f3c67a62 | 74 | * @endcode |
MACRUM | 0:d505f3c67a62 | 75 | */ |
MACRUM | 0:d505f3c67a62 | 76 | class BM1383AGLV |
MACRUM | 0:d505f3c67a62 | 77 | { |
MACRUM | 0:d505f3c67a62 | 78 | public: |
MACRUM | 0:d505f3c67a62 | 79 | /** |
MACRUM | 0:d505f3c67a62 | 80 | * BM1383AGLV constructor |
MACRUM | 0:d505f3c67a62 | 81 | * |
MACRUM | 0:d505f3c67a62 | 82 | * @param sda SDA pin |
MACRUM | 0:d505f3c67a62 | 83 | * @param sdl SCL pin |
MACRUM | 0:d505f3c67a62 | 84 | * @param addr slave address of the I2C peripheral (default: 0xBA) |
MACRUM | 0:d505f3c67a62 | 85 | */ |
MACRUM | 0:d505f3c67a62 | 86 | BM1383AGLV(PinName sda, PinName scl, int addr = BM1383AGLV_DEFAULT_SLAVE_ADDRESS); |
MACRUM | 0:d505f3c67a62 | 87 | |
MACRUM | 0:d505f3c67a62 | 88 | /** |
MACRUM | 0:d505f3c67a62 | 89 | * Create a BM1383AGLV instance which is connected to specified I2C pins |
MACRUM | 0:d505f3c67a62 | 90 | * with specified address |
MACRUM | 0:d505f3c67a62 | 91 | * |
MACRUM | 0:d505f3c67a62 | 92 | * @param i2c_obj I2C object (instance) |
MACRUM | 0:d505f3c67a62 | 93 | * @param addr slave address of the I2C-bus peripheral (default: 0xBA) |
MACRUM | 0:d505f3c67a62 | 94 | */ |
MACRUM | 0:d505f3c67a62 | 95 | BM1383AGLV(I2C &i2c_obj, int addr = BM1383AGLV_DEFAULT_SLAVE_ADDRESS); |
MACRUM | 0:d505f3c67a62 | 96 | |
MACRUM | 0:d505f3c67a62 | 97 | /** |
MACRUM | 0:d505f3c67a62 | 98 | * BM1383AGLV destructor |
MACRUM | 0:d505f3c67a62 | 99 | */ |
MACRUM | 0:d505f3c67a62 | 100 | ~BM1383AGLV(); |
MACRUM | 0:d505f3c67a62 | 101 | |
MACRUM | 0:d505f3c67a62 | 102 | /** Initializa BM1383AGLV sensor |
MACRUM | 0:d505f3c67a62 | 103 | * |
MACRUM | 0:d505f3c67a62 | 104 | * Configure sensor setting |
MACRUM | 0:d505f3c67a62 | 105 | * |
MACRUM | 0:d505f3c67a62 | 106 | */ |
MACRUM | 0:d505f3c67a62 | 107 | void initialize(void); |
MACRUM | 0:d505f3c67a62 | 108 | |
MACRUM | 0:d505f3c67a62 | 109 | /** |
MACRUM | 0:d505f3c67a62 | 110 | * Get pressure |
MACRUM | 0:d505f3c67a62 | 111 | * |
MACRUM | 0:d505f3c67a62 | 112 | * @returns pressure |
MACRUM | 0:d505f3c67a62 | 113 | */ |
MACRUM | 0:d505f3c67a62 | 114 | float getPressure(); |
MACRUM | 0:d505f3c67a62 | 115 | |
MACRUM | 0:d505f3c67a62 | 116 | /** |
MACRUM | 0:d505f3c67a62 | 117 | * Get temerature |
MACRUM | 0:d505f3c67a62 | 118 | * |
MACRUM | 0:d505f3c67a62 | 119 | * @returns temperature |
MACRUM | 0:d505f3c67a62 | 120 | */ |
MACRUM | 0:d505f3c67a62 | 121 | float getTemperature(); |
MACRUM | 0:d505f3c67a62 | 122 | |
MACRUM | 0:d505f3c67a62 | 123 | private: |
MACRUM | 1:997a1eb76a4f | 124 | I2C *i2c_p; |
MACRUM | 1:997a1eb76a4f | 125 | I2C &i2c; |
MACRUM | 0:d505f3c67a62 | 126 | int m_addr; |
MACRUM | 0:d505f3c67a62 | 127 | uint8_t m_buf[3]; |
MACRUM | 0:d505f3c67a62 | 128 | void readRegs(int addr, uint8_t * data, int len); |
MACRUM | 0:d505f3c67a62 | 129 | void writeRegs(uint8_t * data, int len); |
MACRUM | 0:d505f3c67a62 | 130 | |
MACRUM | 0:d505f3c67a62 | 131 | }; |
MACRUM | 0:d505f3c67a62 | 132 | |
MACRUM | 0:d505f3c67a62 | 133 | #endif |