High resolution barometer and altimeter using i2c mode. Adapted to FreeIMU interface

Dependents:   FreeIMU FreeIMU_external_magnetometer FreeIMU

Fork of ms5611 by Kevin Braun

Committer:
tyftyftyf
Date:
Sat Nov 02 17:23:33 2013 +0000
Revision:
7:8545a1d1d1e4
Child:
8:f3660f819e54
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tyftyftyf 7:8545a1d1d1e4 1 /*
tyftyftyf 7:8545a1d1d1e4 2 MS5611-01BA.h - Interfaces a Measurement Specialities MS5611-01BA with Arduino
tyftyftyf 7:8545a1d1d1e4 3 See http://www.meas-spec.com/downloads/MS5611-01BA01.pdf for the device datasheet
tyftyftyf 7:8545a1d1d1e4 4
tyftyftyf 7:8545a1d1d1e4 5 Copyright (C) 2011 Fabio Varesano <fvaresano@yahoo.it>
tyftyftyf 7:8545a1d1d1e4 6
tyftyftyf 7:8545a1d1d1e4 7 Development of this code has been supported by the Department of Computer Science, Universita' degli Studi di Torino, Italy within the Piemonte Project http://www.piemonte.di.unito.it/
tyftyftyf 7:8545a1d1d1e4 8
tyftyftyf 7:8545a1d1d1e4 9
tyftyftyf 7:8545a1d1d1e4 10 This program is free software: you can redistribute it and/or modify
tyftyftyf 7:8545a1d1d1e4 11 it under the terms of the version 3 GNU General Public License as
tyftyftyf 7:8545a1d1d1e4 12 published by the Free Software Foundation.
tyftyftyf 7:8545a1d1d1e4 13
tyftyftyf 7:8545a1d1d1e4 14 This program is distributed in the hope that it will be useful,
tyftyftyf 7:8545a1d1d1e4 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
tyftyftyf 7:8545a1d1d1e4 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tyftyftyf 7:8545a1d1d1e4 17 GNU General Public License for more details.
tyftyftyf 7:8545a1d1d1e4 18
tyftyftyf 7:8545a1d1d1e4 19 You should have received a copy of the GNU General Public License
tyftyftyf 7:8545a1d1d1e4 20 along with this program. If not, see <http://www.gnu.org/licenses/>.
tyftyftyf 7:8545a1d1d1e4 21
tyftyftyf 7:8545a1d1d1e4 22 */
tyftyftyf 7:8545a1d1d1e4 23
tyftyftyf 7:8545a1d1d1e4 24
tyftyftyf 7:8545a1d1d1e4 25
tyftyftyf 7:8545a1d1d1e4 26 #ifndef MS561101BA_h
tyftyftyf 7:8545a1d1d1e4 27 #define MS561101BA_h
tyftyftyf 7:8545a1d1d1e4 28
tyftyftyf 7:8545a1d1d1e4 29 //#define DEBUG_V
tyftyftyf 7:8545a1d1d1e4 30 //#define DEBUG
tyftyftyf 7:8545a1d1d1e4 31 //#include <DebugUtils.h>
tyftyftyf 7:8545a1d1d1e4 32
tyftyftyf 7:8545a1d1d1e4 33 // addresses of the device
tyftyftyf 7:8545a1d1d1e4 34 #define MS561101BA_ADDR_CSB_HIGH 0x76 //CBR=1 0x76 I2C address when CSB is connected to HIGH (VCC)
tyftyftyf 7:8545a1d1d1e4 35 #define MS561101BA_ADDR_CSB_LOW 0x77 //CBR=0 0x77 I2C address when CSB is connected to LOW (GND)
tyftyftyf 7:8545a1d1d1e4 36
tyftyftyf 7:8545a1d1d1e4 37 // registers of the device
tyftyftyf 7:8545a1d1d1e4 38 #define MS561101BA_D1 0x40
tyftyftyf 7:8545a1d1d1e4 39 #define MS561101BA_D2 0x50
tyftyftyf 7:8545a1d1d1e4 40 #define MS561101BA_RESET 0x1E
tyftyftyf 7:8545a1d1d1e4 41
tyftyftyf 7:8545a1d1d1e4 42 // D1 and D2 result size (bytes)
tyftyftyf 7:8545a1d1d1e4 43 #define MS561101BA_D1D2_SIZE 3
tyftyftyf 7:8545a1d1d1e4 44
tyftyftyf 7:8545a1d1d1e4 45 // OSR (Over Sampling Ratio) constants
tyftyftyf 7:8545a1d1d1e4 46 #define MS561101BA_OSR_256 0x00
tyftyftyf 7:8545a1d1d1e4 47 #define MS561101BA_OSR_512 0x02
tyftyftyf 7:8545a1d1d1e4 48 #define MS561101BA_OSR_1024 0x04
tyftyftyf 7:8545a1d1d1e4 49 #define MS561101BA_OSR_2048 0x06
tyftyftyf 7:8545a1d1d1e4 50 #define MS561101BA_OSR_4096 0x08
tyftyftyf 7:8545a1d1d1e4 51
tyftyftyf 7:8545a1d1d1e4 52 #define MS561101BA_PROM_BASE_ADDR 0xA2 // by adding ints from 0 to 6 we can read all the prom configuration values.
tyftyftyf 7:8545a1d1d1e4 53 // C1 will be at 0xA2 and all the subsequent are multiples of 2
tyftyftyf 7:8545a1d1d1e4 54 #define MS561101BA_PROM_REG_COUNT 6 // number of registers in the PROM
tyftyftyf 7:8545a1d1d1e4 55 #define MS561101BA_PROM_REG_SIZE 2 // size in bytes of a prom registry.
tyftyftyf 7:8545a1d1d1e4 56
tyftyftyf 7:8545a1d1d1e4 57 #define I2C_SDA p28
tyftyftyf 7:8545a1d1d1e4 58 #define I2C_SCL p27
tyftyftyf 7:8545a1d1d1e4 59
tyftyftyf 7:8545a1d1d1e4 60 class MS561101BA {
tyftyftyf 7:8545a1d1d1e4 61 public:
tyftyftyf 7:8545a1d1d1e4 62 MS561101BA();
tyftyftyf 7:8545a1d1d1e4 63 MS561101BA(I2C _i2c);
tyftyftyf 7:8545a1d1d1e4 64 void init(uint8_t addr);
tyftyftyf 7:8545a1d1d1e4 65 float getPressure(uint8_t OSR);
tyftyftyf 7:8545a1d1d1e4 66 float getTemperature(uint8_t OSR);
tyftyftyf 7:8545a1d1d1e4 67 int32_t getDeltaTemp(uint8_t OSR);
tyftyftyf 7:8545a1d1d1e4 68 uint32_t rawPressure(uint8_t OSR);
tyftyftyf 7:8545a1d1d1e4 69 uint32_t rawTemperature(uint8_t OSR);
tyftyftyf 7:8545a1d1d1e4 70 int readPROM();
tyftyftyf 7:8545a1d1d1e4 71 void reset();
tyftyftyf 7:8545a1d1d1e4 72 uint32_t lastPresConv, lastTempConv;
tyftyftyf 7:8545a1d1d1e4 73 private:
tyftyftyf 7:8545a1d1d1e4 74 I2C i2c;
tyftyftyf 7:8545a1d1d1e4 75 Timer t;
tyftyftyf 7:8545a1d1d1e4 76 void startConversion(uint8_t command);
tyftyftyf 7:8545a1d1d1e4 77 uint32_t getConversion(uint8_t command);
tyftyftyf 7:8545a1d1d1e4 78 uint8_t _addr;
tyftyftyf 7:8545a1d1d1e4 79 uint16_t _Cal[MS561101BA_PROM_REG_COUNT];
tyftyftyf 7:8545a1d1d1e4 80 uint32_t pressCache, tempCache;
tyftyftyf 7:8545a1d1d1e4 81 };
tyftyftyf 7:8545a1d1d1e4 82
tyftyftyf 7:8545a1d1d1e4 83 #endif // MS561101BA_h