Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
MS5611/MS5611SPI.h@2:4d9204790be1, 2020-05-19 (annotated)
- Committer:
- altb2
- Date:
- Tue May 19 13:13:03 2020 +0000
- Revision:
- 2:4d9204790be1
MS56 Baro-sensor with toggling Temper. and pressure overe i2c;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 2:4d9204790be1 | 1 | /* |
altb2 | 2:4d9204790be1 | 2 | Copyright (c) 2012, Senio Networks, Inc. |
altb2 | 2:4d9204790be1 | 3 | |
altb2 | 2:4d9204790be1 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
altb2 | 2:4d9204790be1 | 5 | of this software and associated documentation files (the "Software"), to deal |
altb2 | 2:4d9204790be1 | 6 | in the Software without restriction, including without limitation the rights |
altb2 | 2:4d9204790be1 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
altb2 | 2:4d9204790be1 | 8 | copies of the Software, and to permit persons to whom the Software is |
altb2 | 2:4d9204790be1 | 9 | furnished to do so, subject to the following conditions: |
altb2 | 2:4d9204790be1 | 10 | |
altb2 | 2:4d9204790be1 | 11 | The above copyright notice and this permission notice shall be included in |
altb2 | 2:4d9204790be1 | 12 | all copies or substantial portions of the Software. |
altb2 | 2:4d9204790be1 | 13 | |
altb2 | 2:4d9204790be1 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
altb2 | 2:4d9204790be1 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
altb2 | 2:4d9204790be1 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
altb2 | 2:4d9204790be1 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
altb2 | 2:4d9204790be1 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
altb2 | 2:4d9204790be1 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
altb2 | 2:4d9204790be1 | 20 | THE SOFTWARE. |
altb2 | 2:4d9204790be1 | 21 | */ |
altb2 | 2:4d9204790be1 | 22 | |
altb2 | 2:4d9204790be1 | 23 | /* MS5611 Modifications |
altb2 | 2:4d9204790be1 | 24 | Aerodyne Labs |
altb2 | 2:4d9204790be1 | 25 | Matthew Nelson - 2014 |
altb2 | 2:4d9204790be1 | 26 | This library was originally the MS5607 library. It has been modified to |
altb2 | 2:4d9204790be1 | 27 | to be used the MS5611 Pressure sensor |
altb2 | 2:4d9204790be1 | 28 | */ |
altb2 | 2:4d9204790be1 | 29 | |
altb2 | 2:4d9204790be1 | 30 | #ifndef MS5611_SPI_H |
altb2 | 2:4d9204790be1 | 31 | #define MS5611_SPI_H |
altb2 | 2:4d9204790be1 | 32 | |
altb2 | 2:4d9204790be1 | 33 | #include "MS5611Base.h" |
altb2 | 2:4d9204790be1 | 34 | |
altb2 | 2:4d9204790be1 | 35 | class MS5611SPI : public MS5611Base { |
altb2 | 2:4d9204790be1 | 36 | public: |
altb2 | 2:4d9204790be1 | 37 | MS5611SPI(PinName mosi, PinName miso, PinName sclk, PinName csb) : spi(mosi, miso, sclk), csb(csb) { |
altb2 | 2:4d9204790be1 | 38 | init(); |
altb2 | 2:4d9204790be1 | 39 | } |
altb2 | 2:4d9204790be1 | 40 | |
altb2 | 2:4d9204790be1 | 41 | private: |
altb2 | 2:4d9204790be1 | 42 | SPI spi; |
altb2 | 2:4d9204790be1 | 43 | DigitalOut csb; |
altb2 | 2:4d9204790be1 | 44 | |
altb2 | 2:4d9204790be1 | 45 | virtual void writeCommand(int command, int ms = 0) { |
altb2 | 2:4d9204790be1 | 46 | csb = 0; |
altb2 | 2:4d9204790be1 | 47 | spi.write(command); |
altb2 | 2:4d9204790be1 | 48 | if (ms) wait_ms(ms); |
altb2 | 2:4d9204790be1 | 49 | csb = 1; |
altb2 | 2:4d9204790be1 | 50 | } |
altb2 | 2:4d9204790be1 | 51 | |
altb2 | 2:4d9204790be1 | 52 | virtual int readPROM(int address) { |
altb2 | 2:4d9204790be1 | 53 | csb = 0; |
altb2 | 2:4d9204790be1 | 54 | spi.write(PROM_READ | address << 1); |
altb2 | 2:4d9204790be1 | 55 | int hi = spi.write(0); |
altb2 | 2:4d9204790be1 | 56 | int low = spi.write(0); |
altb2 | 2:4d9204790be1 | 57 | csb = 1; |
altb2 | 2:4d9204790be1 | 58 | return hi << 8 | low; |
altb2 | 2:4d9204790be1 | 59 | } |
altb2 | 2:4d9204790be1 | 60 | |
altb2 | 2:4d9204790be1 | 61 | virtual int readADC(int command) { |
altb2 | 2:4d9204790be1 | 62 | csb = 0; |
altb2 | 2:4d9204790be1 | 63 | spi.write(ADC_CONV | command); |
altb2 | 2:4d9204790be1 | 64 | static int duration[] = {500, 1100, 2100, 4100, 8220}; |
altb2 | 2:4d9204790be1 | 65 | wait_us(duration[(command & 0x0F) >> 1]); |
altb2 | 2:4d9204790be1 | 66 | csb = 1; |
altb2 | 2:4d9204790be1 | 67 | csb = 0; |
altb2 | 2:4d9204790be1 | 68 | spi.write(ADC_READ); |
altb2 | 2:4d9204790be1 | 69 | int hi = spi.write(0); |
altb2 | 2:4d9204790be1 | 70 | int mid = spi.write(0); |
altb2 | 2:4d9204790be1 | 71 | int low = spi.write(0); |
altb2 | 2:4d9204790be1 | 72 | csb = 1; |
altb2 | 2:4d9204790be1 | 73 | return hi << 16 | mid << 8 | low; |
altb2 | 2:4d9204790be1 | 74 | } |
altb2 | 2:4d9204790be1 | 75 | }; |
altb2 | 2:4d9204790be1 | 76 | |
altb2 | 2:4d9204790be1 | 77 | #endif |