Library to work with the MS5611 pressure sensors. Forked from the MS5607 library

Dependents:   MS5611Example Atlas HC-06_MPU9250_F303K_Stream

Fork of MS5607 by Hiroshi Yamaguchi

Committer:
matgyver
Date:
Tue Jun 24 05:44:17 2014 +0000
Revision:
1:847720b736ea
Parent:
MS5607SPI.h@0:5760862143d1
Updated to work with MS5611

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 0:5760862143d1 1 /*
yamaguch 0:5760862143d1 2 Copyright (c) 2012, Senio Networks, Inc.
yamaguch 0:5760862143d1 3
yamaguch 0:5760862143d1 4 Permission is hereby granted, free of charge, to any person obtaining a copy
yamaguch 0:5760862143d1 5 of this software and associated documentation files (the "Software"), to deal
yamaguch 0:5760862143d1 6 in the Software without restriction, including without limitation the rights
yamaguch 0:5760862143d1 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yamaguch 0:5760862143d1 8 copies of the Software, and to permit persons to whom the Software is
yamaguch 0:5760862143d1 9 furnished to do so, subject to the following conditions:
yamaguch 0:5760862143d1 10
yamaguch 0:5760862143d1 11 The above copyright notice and this permission notice shall be included in
yamaguch 0:5760862143d1 12 all copies or substantial portions of the Software.
yamaguch 0:5760862143d1 13
yamaguch 0:5760862143d1 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yamaguch 0:5760862143d1 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yamaguch 0:5760862143d1 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yamaguch 0:5760862143d1 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yamaguch 0:5760862143d1 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yamaguch 0:5760862143d1 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yamaguch 0:5760862143d1 20 THE SOFTWARE.
yamaguch 0:5760862143d1 21 */
yamaguch 0:5760862143d1 22
matgyver 1:847720b736ea 23 /* MS5611 Modifications
matgyver 1:847720b736ea 24 Aerodyne Labs
matgyver 1:847720b736ea 25 Matthew Nelson - 2014
matgyver 1:847720b736ea 26 This library was originally the MS5607 library. It has been modified to
matgyver 1:847720b736ea 27 to be used the MS5611 Pressure sensor
matgyver 1:847720b736ea 28 */
yamaguch 0:5760862143d1 29
matgyver 1:847720b736ea 30 #ifndef MS5611_SPI_H
matgyver 1:847720b736ea 31 #define MS5611_SPI_H
yamaguch 0:5760862143d1 32
matgyver 1:847720b736ea 33 #include "MS5611Base.h"
matgyver 1:847720b736ea 34
matgyver 1:847720b736ea 35 class MS5611SPI : public MS5611Base {
yamaguch 0:5760862143d1 36 public:
matgyver 1:847720b736ea 37 MS5611SPI(PinName mosi, PinName miso, PinName sclk, PinName csb) : spi(mosi, miso, sclk), csb(csb) {
yamaguch 0:5760862143d1 38 init();
yamaguch 0:5760862143d1 39 }
yamaguch 0:5760862143d1 40
yamaguch 0:5760862143d1 41 private:
yamaguch 0:5760862143d1 42 SPI spi;
yamaguch 0:5760862143d1 43 DigitalOut csb;
yamaguch 0:5760862143d1 44
yamaguch 0:5760862143d1 45 virtual void writeCommand(int command, int ms = 0) {
yamaguch 0:5760862143d1 46 csb = 0;
yamaguch 0:5760862143d1 47 spi.write(command);
yamaguch 0:5760862143d1 48 if (ms) wait_ms(ms);
yamaguch 0:5760862143d1 49 csb = 1;
yamaguch 0:5760862143d1 50 }
yamaguch 0:5760862143d1 51
yamaguch 0:5760862143d1 52 virtual int readPROM(int address) {
yamaguch 0:5760862143d1 53 csb = 0;
yamaguch 0:5760862143d1 54 spi.write(PROM_READ | address << 1);
yamaguch 0:5760862143d1 55 int hi = spi.write(0);
yamaguch 0:5760862143d1 56 int low = spi.write(0);
yamaguch 0:5760862143d1 57 csb = 1;
yamaguch 0:5760862143d1 58 return hi << 8 | low;
yamaguch 0:5760862143d1 59 }
yamaguch 0:5760862143d1 60
yamaguch 0:5760862143d1 61 virtual int readADC(int command) {
yamaguch 0:5760862143d1 62 csb = 0;
yamaguch 0:5760862143d1 63 spi.write(ADC_CONV | command);
yamaguch 0:5760862143d1 64 static int duration[] = {500, 1100, 2100, 4100, 8220};
yamaguch 0:5760862143d1 65 wait_us(duration[(command & 0x0F) >> 1]);
yamaguch 0:5760862143d1 66 csb = 1;
yamaguch 0:5760862143d1 67 csb = 0;
yamaguch 0:5760862143d1 68 spi.write(ADC_READ);
yamaguch 0:5760862143d1 69 int hi = spi.write(0);
yamaguch 0:5760862143d1 70 int mid = spi.write(0);
yamaguch 0:5760862143d1 71 int low = spi.write(0);
yamaguch 0:5760862143d1 72 csb = 1;
yamaguch 0:5760862143d1 73 return hi << 16 | mid << 8 | low;
yamaguch 0:5760862143d1 74 }
yamaguch 0:5760862143d1 75 };
yamaguch 0:5760862143d1 76
yamaguch 0:5760862143d1 77 #endif