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: IZU2020_AVIONICS qqq_izu_main_test IZU2020_AVIONICS Hybrid_OB2021_MAIN
PQLPS22HB.cpp
00001 #include "mbed.h" 00002 #include "PQLPS22HB.h" 00003 00004 LPS22HB :: LPS22HB (I2C &i2c, SA0_t SA0) 00005 { 00006 _addr = SA0; 00007 _i2c = &i2c; 00008 _i2c -> frequency(400000); 00009 } 00010 00011 void LPS22HB :: begin() 00012 { 00013 cmd[0] = LPS22HB_CTRL_REG1; 00014 cmd[1] = 0x40; 00015 _i2c -> write(_addr, cmd, 2); 00016 } 00017 00018 bool LPS22HB :: test() 00019 { 00020 cmd[0] = LPS22HB_WHO_AM_I; 00021 _i2c -> write(_addr, cmd, 1); 00022 _i2c -> read(_addr, buff, 1); 00023 if(buff[0] == 0xB1) { 00024 return true; 00025 } else { 00026 return false; 00027 } 00028 } 00029 00030 void LPS22HB :: read(float *press, float *temp) 00031 { 00032 read_press(press); 00033 read_temp(temp); 00034 } 00035 00036 void LPS22HB :: read_press(float *press) 00037 { 00038 cmd[0] = LPS22HB_PRESS_XL; 00039 _i2c -> write(_addr, cmd, 1); 00040 _i2c -> read(_addr, buff, 3); 00041 *press = (int)(buff[0] | buff[1] << 8 | buff[2] << 16) / 4096.0f; 00042 } 00043 00044 void LPS22HB :: read_temp(float *temp) 00045 { 00046 cmd[0] = LPS22HB_TEMP_L; 00047 _i2c -> write(_addr, cmd, 1); 00048 _i2c -> read(_addr, buff, 2); 00049 *temp = (short)(buff[0] | buff[1] << 8) * 0.01; 00050 }
Generated on Sun Jul 17 2022 16:56:55 by
1.7.2