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.
Dependents: Drones-Controlador controladoatitude_cteste Drone_Controlador_Atitude optical_test
Diff: LPS25H/LPS25H.cpp
- Revision:
- 3:2f2b8e863991
- Child:
- 4:d55264b2cad5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPS25H/LPS25H.cpp Thu Apr 19 19:41:02 2018 +0000 @@ -0,0 +1,47 @@ +#include "LPS25H.h" + +/** Class constructor */ +LPS25H::LPS25H(PinName sda, PinName scl) : i2c(sda, scl) +{ +} + +/** Initialize barometer */ +void LPS25H::setup() +{ + // LPS25H I2C address + char address = LPS25H_ADDRESS; + // Register address and data that we're going to write + char reg_data[2] = {CTRL_REG1, 0b10110000}; + + // Point to register address and write data into this address + i2c.write(address, reg_data, 2); +} + +/** Read barometer */ +void LPS25H::read() +{ + read_baro(); +} + +/** Read barometer output data */ +void LPS25H::read_baro() +{ + // LPS25H I2C address + char address = LPS25H_ADDRESS; + // Register address + char reg[1] = {PRESS_OUT_XL | (1 << 7)}; + // Data that we're going to read + char data[3]; + + // Point to register address + i2c.write(address, reg, 1); + // Read data from this address (register address will auto-increment and all three axis information (two 8 bit data each) will be read) + i2c.read(address, data, 3); + + // Reassemble the data (three 8 bit data into one 24 bit data) + int32_t p_raw = (data[2] << 16 ) | (data[1] << 8 ) | data[0]; + // Convert to SI units + p = p_raw / 4096.0; + // + z = 44330.8f*(1.0f-pow((p/1025.0f),0.190263f)); +} \ No newline at end of file