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/MS5611I2C.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_I2C_H |
altb2 | 2:4d9204790be1 | 31 | #define MS5611_I2C_H |
altb2 | 2:4d9204790be1 | 32 | |
altb2 | 2:4d9204790be1 | 33 | #include "MS5611Base.h" |
altb2 | 2:4d9204790be1 | 34 | |
altb2 | 2:4d9204790be1 | 35 | extern Serial pc; |
altb2 | 2:4d9204790be1 | 36 | |
altb2 | 2:4d9204790be1 | 37 | class MS5611I2C : public MS5611Base { |
altb2 | 2:4d9204790be1 | 38 | public: |
altb2 | 2:4d9204790be1 | 39 | MS5611I2C(I2C &i2c, int csb = 0) : i2c(i2c), i2cAddr(csb ? 0xEC : 0xEE) { |
altb2 | 2:4d9204790be1 | 40 | wait(.01); |
altb2 | 2:4d9204790be1 | 41 | i2c.frequency(400000); |
altb2 | 2:4d9204790be1 | 42 | wait(.01); |
altb2 | 2:4d9204790be1 | 43 | init(); |
altb2 | 2:4d9204790be1 | 44 | ADC_toggler = false; |
altb2 | 2:4d9204790be1 | 45 | } |
altb2 | 2:4d9204790be1 | 46 | |
altb2 | 2:4d9204790be1 | 47 | private: |
altb2 | 2:4d9204790be1 | 48 | I2C &i2c; |
altb2 | 2:4d9204790be1 | 49 | int i2cAddr; |
altb2 | 2:4d9204790be1 | 50 | bool ADC_toggler; |
altb2 | 2:4d9204790be1 | 51 | |
altb2 | 2:4d9204790be1 | 52 | virtual void writeCommand(int command, int ms = 0) { |
altb2 | 2:4d9204790be1 | 53 | char buf[1]; |
altb2 | 2:4d9204790be1 | 54 | buf[0] = command; |
altb2 | 2:4d9204790be1 | 55 | i2c.write(i2cAddr, buf, 1); |
altb2 | 2:4d9204790be1 | 56 | if (ms) wait_ms(ms); |
altb2 | 2:4d9204790be1 | 57 | } |
altb2 | 2:4d9204790be1 | 58 | |
altb2 | 2:4d9204790be1 | 59 | virtual int readPROM(int address) { |
altb2 | 2:4d9204790be1 | 60 | char buf[2]; |
altb2 | 2:4d9204790be1 | 61 | buf[0] = (PROM_READ | (address << 1)); |
altb2 | 2:4d9204790be1 | 62 | |
altb2 | 2:4d9204790be1 | 63 | if (i2c.write(i2cAddr, buf, 1) == 0 && |
altb2 | 2:4d9204790be1 | 64 | i2c.read(i2cAddr, buf, 2) == 0) |
altb2 | 2:4d9204790be1 | 65 | return buf[0] << 8 | buf[1]; |
altb2 | 2:4d9204790be1 | 66 | |
altb2 | 2:4d9204790be1 | 67 | return -1; |
altb2 | 2:4d9204790be1 | 68 | } |
altb2 | 2:4d9204790be1 | 69 | |
altb2 | 2:4d9204790be1 | 70 | virtual int readADC(int command) { |
altb2 | 2:4d9204790be1 | 71 | char cmd[1]; |
altb2 | 2:4d9204790be1 | 72 | cmd[0] = (ADC_CONV | command); |
altb2 | 2:4d9204790be1 | 73 | if (i2c.write(i2cAddr, cmd, 1) == 0) { |
altb2 | 2:4d9204790be1 | 74 | static int duration[] = {500, 1100, 2100, 4100, 8220}; // OSR_4096 |
altb2 | 2:4d9204790be1 | 75 | wait_us(duration[(command & 0x0F) >> 1]); |
altb2 | 2:4d9204790be1 | 76 | cmd[0] = ADC_READ; |
altb2 | 2:4d9204790be1 | 77 | char buf[3]; |
altb2 | 2:4d9204790be1 | 78 | if (i2c.write(i2cAddr, cmd, sizeof(cmd)) == 0 && |
altb2 | 2:4d9204790be1 | 79 | i2c.read(i2cAddr, buf, sizeof(buf)) == 0){ |
altb2 | 2:4d9204790be1 | 80 | return buf[0] << 16 | buf[1] << 8 | buf[2]; |
altb2 | 2:4d9204790be1 | 81 | } |
altb2 | 2:4d9204790be1 | 82 | } |
altb2 | 2:4d9204790be1 | 83 | return -1; |
altb2 | 2:4d9204790be1 | 84 | } |
altb2 | 2:4d9204790be1 | 85 | virtual int readADC_write(int command) { |
altb2 | 2:4d9204790be1 | 86 | char cmd[1]; |
altb2 | 2:4d9204790be1 | 87 | cmd[0] = (ADC_CONV | command); |
altb2 | 2:4d9204790be1 | 88 | return (i2c.write(i2cAddr, cmd, 1)==0); |
altb2 | 2:4d9204790be1 | 89 | } |
altb2 | 2:4d9204790be1 | 90 | |
altb2 | 2:4d9204790be1 | 91 | virtual int readADC_read(int command) { |
altb2 | 2:4d9204790be1 | 92 | char cmd[1]; |
altb2 | 2:4d9204790be1 | 93 | cmd[0] = ADC_READ; |
altb2 | 2:4d9204790be1 | 94 | char buf[3]; |
altb2 | 2:4d9204790be1 | 95 | if (i2c.write(i2cAddr, cmd, sizeof(cmd)) == 0 && |
altb2 | 2:4d9204790be1 | 96 | i2c.read(i2cAddr, buf, sizeof(buf)) == 0){ |
altb2 | 2:4d9204790be1 | 97 | return buf[0] << 16 | buf[1] << 8 | buf[2]; |
altb2 | 2:4d9204790be1 | 98 | } |
altb2 | 2:4d9204790be1 | 99 | return -1; |
altb2 | 2:4d9204790be1 | 100 | } |
altb2 | 2:4d9204790be1 | 101 | }; |
altb2 | 2:4d9204790be1 | 102 | |
altb2 | 2:4d9204790be1 | 103 | #endif |