k
MPL3115.cpp@0:2cc0f6ef330f, 2016-01-23 (annotated)
- Committer:
- AswinSivakumar
- Date:
- Sat Jan 23 00:07:22 2016 +0000
- Revision:
- 0:2cc0f6ef330f
- Child:
- 1:117534dd5101
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AswinSivakumar | 0:2cc0f6ef330f | 1 | /* Copyright (c) 2015 NXP Semiconductors. MIT License |
AswinSivakumar | 0:2cc0f6ef330f | 2 | * |
AswinSivakumar | 0:2cc0f6ef330f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
AswinSivakumar | 0:2cc0f6ef330f | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
AswinSivakumar | 0:2cc0f6ef330f | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
AswinSivakumar | 0:2cc0f6ef330f | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
AswinSivakumar | 0:2cc0f6ef330f | 7 | * Software is furnished to do so, subject to the following conditions: |
AswinSivakumar | 0:2cc0f6ef330f | 8 | * |
AswinSivakumar | 0:2cc0f6ef330f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
AswinSivakumar | 0:2cc0f6ef330f | 10 | * substantial portions of the Software. |
AswinSivakumar | 0:2cc0f6ef330f | 11 | * |
AswinSivakumar | 0:2cc0f6ef330f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
AswinSivakumar | 0:2cc0f6ef330f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
AswinSivakumar | 0:2cc0f6ef330f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
AswinSivakumar | 0:2cc0f6ef330f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
AswinSivakumar | 0:2cc0f6ef330f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
AswinSivakumar | 0:2cc0f6ef330f | 17 | */ |
AswinSivakumar | 0:2cc0f6ef330f | 18 | |
AswinSivakumar | 0:2cc0f6ef330f | 19 | #include "MPL3115.h" |
AswinSivakumar | 0:2cc0f6ef330f | 20 | #include "mbed.h" |
AswinSivakumar | 0:2cc0f6ef330f | 21 | |
AswinSivakumar | 0:2cc0f6ef330f | 22 | MPL3115::MPL3115(PinName sda, PinName scl) : MPL3115_i2c(sda,scl) |
AswinSivakumar | 0:2cc0f6ef330f | 23 | { |
AswinSivakumar | 0:2cc0f6ef330f | 24 | |
AswinSivakumar | 0:2cc0f6ef330f | 25 | } |
AswinSivakumar | 0:2cc0f6ef330f | 26 | |
AswinSivakumar | 0:2cc0f6ef330f | 27 | void MPL3115::MPL3115_config(void) |
AswinSivakumar | 0:2cc0f6ef330f | 28 | { |
AswinSivakumar | 0:2cc0f6ef330f | 29 | char d[2]; |
AswinSivakumar | 0:2cc0f6ef330f | 30 | d[0] = MPL3115_CTRL_REG1; //Puts device in Standby mode |
AswinSivakumar | 0:2cc0f6ef330f | 31 | d[1] = 0x00; |
AswinSivakumar | 0:2cc0f6ef330f | 32 | MPL3115_i2c.write(MPL3115_I2C_ADDRESS, d,2); |
AswinSivakumar | 0:2cc0f6ef330f | 33 | |
AswinSivakumar | 0:2cc0f6ef330f | 34 | |
AswinSivakumar | 0:2cc0f6ef330f | 35 | d[0] = MPL3115_CTRL_REG1; //Puts device in Active mode and in altimeter mode |
AswinSivakumar | 0:2cc0f6ef330f | 36 | d[1] = 0x81; |
AswinSivakumar | 0:2cc0f6ef330f | 37 | MPL3115_i2c.write(MPL3115_I2C_ADDRESS, d, 2); |
AswinSivakumar | 0:2cc0f6ef330f | 38 | |
AswinSivakumar | 0:2cc0f6ef330f | 39 | } |
AswinSivakumar | 0:2cc0f6ef330f | 40 | |
AswinSivakumar | 0:2cc0f6ef330f | 41 | |
AswinSivakumar | 0:2cc0f6ef330f | 42 | |
AswinSivakumar | 0:2cc0f6ef330f | 43 | void MPL3115::acquire_MPL3115_data_Altitude_in_m(float * alt_data) |
AswinSivakumar | 0:2cc0f6ef330f | 44 | { |
AswinSivakumar | 0:2cc0f6ef330f | 45 | |
AswinSivakumar | 0:2cc0f6ef330f | 46 | char data_bytes[7]; |
AswinSivakumar | 0:2cc0f6ef330f | 47 | char d[1]; |
AswinSivakumar | 0:2cc0f6ef330f | 48 | d[0]=MPL3115_STATUS; |
AswinSivakumar | 0:2cc0f6ef330f | 49 | MPL3115_i2c.write(MPL3115_I2C_ADDRESS,d,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes. |
AswinSivakumar | 0:2cc0f6ef330f | 50 | MPL3115_i2c.read(MPL3115_I2C_ADDRESS,data_bytes,5); |
AswinSivakumar | 0:2cc0f6ef330f | 51 | alt_data[0]= (float)((short)((data_bytes[1] << 8 ) | data_bytes[2])) + (float)(data_bytes[3]>>4) * 0.0625; |
AswinSivakumar | 0:2cc0f6ef330f | 52 | |
AswinSivakumar | 0:2cc0f6ef330f | 53 | |
AswinSivakumar | 0:2cc0f6ef330f | 54 | } |