BMP280 pressure sensor library with SPI interface

Dependents:   BMP280_SPI_Hello Cansat_of_kada_ver2 bmp280

Committer:
MACRUM
Date:
Thu Feb 08 09:56:31 2018 +0000
Revision:
0:0463be4e35c0
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:0463be4e35c0 1 /**
MACRUM 0:0463be4e35c0 2 ******************************************************************************
MACRUM 0:0463be4e35c0 3 * @file BMP280_SPI.h
MACRUM 0:0463be4e35c0 4 * @author Toyomasa Watarai
MACRUM 0:0463be4e35c0 5 * @version V1.0.0
MACRUM 0:0463be4e35c0 6 * @date 8 Feb 2018
MACRUM 0:0463be4e35c0 7 * @brief This file contains the class of a BMP280 Digital pressure sensor library with SPI interface
MACRUM 0:0463be4e35c0 8 ******************************************************************************
MACRUM 0:0463be4e35c0 9 * @attention
MACRUM 0:0463be4e35c0 10 *
MACRUM 0:0463be4e35c0 11 * Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 0:0463be4e35c0 12 * you may not use this file except in compliance with the License.
MACRUM 0:0463be4e35c0 13 * You may obtain a copy of the License at
MACRUM 0:0463be4e35c0 14 *
MACRUM 0:0463be4e35c0 15 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:0463be4e35c0 16 *
MACRUM 0:0463be4e35c0 17 * Unless required by applicable law or agreed to in writing, software
MACRUM 0:0463be4e35c0 18 * distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 0:0463be4e35c0 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:0463be4e35c0 20 * See the License for the specific language governing permissions and
MACRUM 0:0463be4e35c0 21 * limitations under the License.
MACRUM 0:0463be4e35c0 22 */
MACRUM 0:0463be4e35c0 23
MACRUM 0:0463be4e35c0 24
MACRUM 0:0463be4e35c0 25 #ifndef MBED_BMP280_SPI_H
MACRUM 0:0463be4e35c0 26 #define MBED_BMP280_SPI_H
MACRUM 0:0463be4e35c0 27
MACRUM 0:0463be4e35c0 28 #include "mbed.h"
MACRUM 0:0463be4e35c0 29
MACRUM 0:0463be4e35c0 30 #ifdef _DEBUG
MACRUM 0:0463be4e35c0 31 extern Serial pc;
MACRUM 0:0463be4e35c0 32 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__)
MACRUM 0:0463be4e35c0 33 #else
MACRUM 0:0463be4e35c0 34 #define DEBUG_PRINT(...)
MACRUM 0:0463be4e35c0 35 #endif
MACRUM 0:0463be4e35c0 36
MACRUM 0:0463be4e35c0 37 /** Interface for controlling BMP280 pressure sensor
MACRUM 0:0463be4e35c0 38 *
MACRUM 0:0463be4e35c0 39 * @code
MACRUM 0:0463be4e35c0 40 * #include "mbed.h"
MACRUM 0:0463be4e35c0 41 * #include "BMP280_SPI.h"
MACRUM 0:0463be4e35c0 42 *
MACRUM 0:0463be4e35c0 43 * Serial pc(USBTX, USBRX);
MACRUM 0:0463be4e35c0 44 * BMP280_SPI sensor(D11, D12, D13, D9); // mosi, miso, sclk, cs
MACRUM 0:0463be4e35c0 45 *
MACRUM 0:0463be4e35c0 46 * int main() {
MACRUM 0:0463be4e35c0 47 *
MACRUM 0:0463be4e35c0 48 * while(1) {
MACRUM 0:0463be4e35c0 49 * pc.printf("%2.2f degC, %04.2f hPa\n", sensor.getTemperature(), sensor.getPressure());
MACRUM 0:0463be4e35c0 50 * wait(1);
MACRUM 0:0463be4e35c0 51 * }
MACRUM 0:0463be4e35c0 52 * }
MACRUM 0:0463be4e35c0 53 *
MACRUM 0:0463be4e35c0 54 * @endcode
MACRUM 0:0463be4e35c0 55 */
MACRUM 0:0463be4e35c0 56
MACRUM 0:0463be4e35c0 57 /** BMP280_SPI class
MACRUM 0:0463be4e35c0 58 *
MACRUM 0:0463be4e35c0 59 * BMP280_SPI: A library to correct data using Boshe BMP280 pressure sensor device
MACRUM 0:0463be4e35c0 60 *
MACRUM 0:0463be4e35c0 61 */
MACRUM 0:0463be4e35c0 62 class BMP280_SPI
MACRUM 0:0463be4e35c0 63 {
MACRUM 0:0463be4e35c0 64 public:
MACRUM 0:0463be4e35c0 65
MACRUM 0:0463be4e35c0 66 enum spi_mask {
MACRUM 0:0463be4e35c0 67 BMP280_SPI_WRITE = 0x7F
MACRUM 0:0463be4e35c0 68 };
MACRUM 0:0463be4e35c0 69
MACRUM 0:0463be4e35c0 70 /** Create a BMP280 instance
MACRUM 0:0463be4e35c0 71 * which is connected to specified SPI pins
MACRUM 0:0463be4e35c0 72 *
MACRUM 0:0463be4e35c0 73 * @param mosi SPI MOSI pin
MACRUM 0:0463be4e35c0 74 * @param miso SPI MISO pin
MACRUM 0:0463be4e35c0 75 * @param sclk SPI SCLK pin
MACRUM 0:0463be4e35c0 76 * @param cs device CS pin
MACRUM 0:0463be4e35c0 77 */
MACRUM 0:0463be4e35c0 78 BMP280_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs);
MACRUM 0:0463be4e35c0 79
MACRUM 0:0463be4e35c0 80 /** Destructor of BMP280_SPI
MACRUM 0:0463be4e35c0 81 */
MACRUM 0:0463be4e35c0 82 virtual ~BMP280_SPI();
MACRUM 0:0463be4e35c0 83
MACRUM 0:0463be4e35c0 84 /** Initializa BMP280 sensor
MACRUM 0:0463be4e35c0 85 *
MACRUM 0:0463be4e35c0 86 * Configure sensor setting and read parameters for calibration
MACRUM 0:0463be4e35c0 87 *
MACRUM 0:0463be4e35c0 88 */
MACRUM 0:0463be4e35c0 89 void initialize(void);
MACRUM 0:0463be4e35c0 90
MACRUM 0:0463be4e35c0 91 /** Read the current temperature value (degree Celsius) from BMP280 sensor
MACRUM 0:0463be4e35c0 92 *
MACRUM 0:0463be4e35c0 93 * @return Temperature value (degree Celsius)
MACRUM 0:0463be4e35c0 94 */
MACRUM 0:0463be4e35c0 95 float getTemperature(void);
MACRUM 0:0463be4e35c0 96
MACRUM 0:0463be4e35c0 97 /** Read the current pressure value (hectopascal) from BMP280 sensor
MACRUM 0:0463be4e35c0 98 *
MACRUM 0:0463be4e35c0 99 * @return Pressure value (hectopascal)
MACRUM 0:0463be4e35c0 100 */
MACRUM 0:0463be4e35c0 101 float getPressure(void);
MACRUM 0:0463be4e35c0 102
MACRUM 0:0463be4e35c0 103 private:
MACRUM 0:0463be4e35c0 104
MACRUM 0:0463be4e35c0 105 SPI _spi;
MACRUM 0:0463be4e35c0 106 DigitalOut _cs;
MACRUM 0:0463be4e35c0 107 uint16_t dig_T1;
MACRUM 0:0463be4e35c0 108 int16_t dig_T2, dig_T3;
MACRUM 0:0463be4e35c0 109 uint16_t dig_P1;
MACRUM 0:0463be4e35c0 110 int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9;
MACRUM 0:0463be4e35c0 111 int32_t t_fine;
MACRUM 0:0463be4e35c0 112
MACRUM 0:0463be4e35c0 113 };
MACRUM 0:0463be4e35c0 114
MACRUM 0:0463be4e35c0 115 #endif // MBED_BMP280_SPI_H