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
LPS25H/LPS25H.cpp
- Committer:
- fbob
- Date:
- 2018-04-19
- Revision:
- 4:d55264b2cad5
- Parent:
- 3:2f2b8e863991
File content as of revision 4:d55264b2cad5:
#include "LPS25H.h" /** Class constructor */ LPS25H::LPS25H(PinName sda, PinName scl) : i2c(sda, scl) { } /** Init barometer */ void LPS25H::init() { init_baro(); } /** Read barometer */ void LPS25H::read() { read_baro(); } /** Initialize barometer */ void LPS25H::init_baro() { // 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_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)); }