STMicroelectronics LPS331 I2C Library.
Dependents: LPS331_HelloWorld mbed_vfd_thermometer lon-lof
LPS331_I2C.h
00001 /* 00002 * I2C/SPI digital pressure sensor "LPS331AP" library for I2C mode. 00003 * 00004 * http://www.st.com/web/en/resource/technical/document/datasheet/DM00036196.pdf 00005 * 00006 * Copyright(c) -2013 unos@NYAMFG, 00007 * Released under the MIT License: http://mbed.org/license/mit 00008 * 00009 * revision 1.1 22-Oct-2013 Add multibyte read, Change temperature and pressure reading method. 00010 * revision 1.0 20-Oct-2013 1st release, Does not support interrupts. 00011 */ 00012 00013 #ifndef LPS331_I2C_H 00014 #define LPS331_I2C_H 00015 00016 #include "mbed.h" 00017 00018 // SA0 status configuration values. 00019 #define LPS331_I2C_SA0_HIGH true 00020 #define LPS331_I2C_SA0_LOW false 00021 00022 // Pressure configuration values. 00023 #define LPS331_I2C_PRESSURE_AVG_1 0x00 00024 #define LPS331_I2C_PRESSURE_AVG_2 0x01 00025 #define LPS331_I2C_PRESSURE_AVG_4 0x02 00026 #define LPS331_I2C_PRESSURE_AVG_8 0x03 00027 #define LPS331_I2C_PRESSURE_AVG_16 0x04 00028 #define LPS331_I2C_PRESSURE_AVG_32 0x05 00029 #define LPS331_I2C_PRESSURE_AVG_64 0x06 00030 #define LPS331_I2C_PRESSURE_AVG_128 0x07 00031 #define LPS331_I2C_PRESSURE_AVG_256 0x08 00032 #define LPS331_I2C_PRESSURE_AVG_384 0x09 00033 #define LPS331_I2C_PRESSURE_AVG_512 0x0a 00034 00035 // Temperature configuration values. 00036 #define LPS331_I2C_TEMP_AVG_1 0x00 00037 #define LPS331_I2C_TEMP_AVG_2 0x01 00038 #define LPS331_I2C_TEMP_AVG_4 0x02 00039 #define LPS331_I2C_TEMP_AVG_8 0x03 00040 #define LPS331_I2C_TEMP_AVG_16 0x04 00041 #define LPS331_I2C_TEMP_AVG_32 0x05 00042 #define LPS331_I2C_TEMP_AVG_64 0x06 00043 #define LPS331_I2C_TEMP_AVG_128 0x07 00044 00045 // Data Rate Pressure / Temperature 00046 #define LPS331_I2C_DATARATE_ONESHOT 0x00 // OneShot OneShot 00047 #define LPS331_I2C_DATARATE_1HZ 0x01 // 1Hz 1Hz 00048 #define LPS331_I2C_DATARATE_7HZ 0x02 // 7Hz 1Hz 00049 #define LPS331_I2C_DATARATE_12_5HZ 0x03 // 12.5Hz 1Hz 00050 #define LPS331_I2C_DATARATE_25HZ 0x04 // 25Hz 1Hz 00051 #define LPS331_I2C_DATARATE_7HZ_T 0x05 // 7Hz 7Hz 00052 #define LPS331_I2C_DATARATE_12_5HZ_T 0x06 // 12.5Hz 12.5Hz 00053 #define LPS331_I2C_DATARATE_25HZ_T 0x07 // 25Hz 25Hz (*) 00054 // (*) Not allowed with PRESSURE_AVG_512 & TEMP_AVG_128. 00055 // More information , see datasheet. 00056 00057 // I2C Address. 00058 #define LPS331_I2C_ADDRESS_SA0_HIGH 0xba 00059 #define LPS331_I2C_ADDRESS_SA0_LOW 0xb8 00060 00061 class LPS331_I2C 00062 { 00063 public: 00064 LPS331_I2C(PinName sda, PinName scl, bool sa0); 00065 ~LPS331_I2C(); 00066 00067 char whoami(); 00068 bool isAvailable(); 00069 00070 void setResolution(char pressure_avg, char temp_avg); 00071 void setActive(bool is_active); 00072 void setDataRate(char datarate); 00073 00074 float getPressure(); 00075 float getTemperature(); 00076 00077 void _write(char subaddress, char data); 00078 char _read(char subaddress); 00079 void _read_multibyte(char startsubaddress, char* data, char count); 00080 00081 private: 00082 I2C _i2c; 00083 char _address; 00084 char _ctrlreg1; 00085 }; 00086 00087 00088 #endif /* LPC331_I2C_H */ 00089
Generated on Thu Jul 21 2022 18:52:16 by 1.7.2