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:
Wed Apr 18 20:24:20 2018 +0000
Revision:
10:7802dc3ef0a0
Parent:
8:f3660f819e54
change to I2C 1

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 8:f3660f819e54 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 class MS561101BA {
tyftyftyf 7:8545a1d1d1e4 58 public:
tyftyftyf 7:8545a1d1d1e4 59 MS561101BA();
tyftyftyf 7:8545a1d1d1e4 60 void init(uint8_t addr);
tyftyftyf 8:f3660f819e54 61 float getPressure();
tyftyftyf 8:f3660f819e54 62 float getTemperature();
tyftyftyf 8:f3660f819e54 63 int32_t getDeltaTemp();
tyftyftyf 8:f3660f819e54 64 void start_sampling(uint8_t OSR);
tyftyftyf 8:f3660f819e54 65 int rawTemperature();
tyftyftyf 8:f3660f819e54 66 int rawPressure();
tyftyftyf 7:8545a1d1d1e4 67 int readPROM();
tyftyftyf 7:8545a1d1d1e4 68 void reset();
tyftyftyf 7:8545a1d1d1e4 69 uint32_t lastPresConv, lastTempConv;
tyftyftyf 8:f3660f819e54 70
tyftyftyf 8:f3660f819e54 71 MODI2C i2c;
tyftyftyf 8:f3660f819e54 72
tyftyftyf 8:f3660f819e54 73 static void samplingthread_stub(void const *p);
tyftyftyf 8:f3660f819e54 74 void samplingthread();
tyftyftyf 8:f3660f819e54 75 Thread _thread;
tyftyftyf 8:f3660f819e54 76 volatile uint32_t conversion;
tyftyftyf 8:f3660f819e54 77 uint8_t _OSR;
tyftyftyf 8:f3660f819e54 78 Semaphore sem;
tyftyftyf 8:f3660f819e54 79 char cobuf[3];
tyftyftyf 8:f3660f819e54 80
tyftyftyf 7:8545a1d1d1e4 81 Timer t;
tyftyftyf 8:f3660f819e54 82 void startConversion(char *command);
tyftyftyf 8:f3660f819e54 83 void getConversion();
tyftyftyf 7:8545a1d1d1e4 84 uint8_t _addr;
tyftyftyf 7:8545a1d1d1e4 85 uint16_t _Cal[MS561101BA_PROM_REG_COUNT];
tyftyftyf 7:8545a1d1d1e4 86 uint32_t pressCache, tempCache;
tyftyftyf 8:f3660f819e54 87
tyftyftyf 8:f3660f819e54 88 char zero;
tyftyftyf 8:f3660f819e54 89 char MS561101BA_RESET;
tyftyftyf 7:8545a1d1d1e4 90 };
tyftyftyf 7:8545a1d1d1e4 91
tyftyftyf 7:8545a1d1d1e4 92 #endif // MS561101BA_h