STMicroelectronics LPS331 I2C Library.

Dependents:   LPS331_HelloWorld mbed_vfd_thermometer lon-lof

Committer:
nyamfg
Date:
Sun Oct 20 15:22:55 2013 +0000
Revision:
0:3fd57444bc65
Child:
1:b7d3d6e82049
1st release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyamfg 0:3fd57444bc65 1 /*
nyamfg 0:3fd57444bc65 2 * I2C/SPI digital pressure sensor "LPS331AP" library for I2C mode.
nyamfg 0:3fd57444bc65 3 *
nyamfg 0:3fd57444bc65 4 * http://www.st.com/web/en/resource/technical/document/datasheet/DM00036196.pdf
nyamfg 0:3fd57444bc65 5 *
nyamfg 0:3fd57444bc65 6 * Copyright(c) -2013 unos@NYAMFG,
nyamfg 0:3fd57444bc65 7 * Released under the MIT License: http://mbed.org/license/mit
nyamfg 0:3fd57444bc65 8 *
nyamfg 0:3fd57444bc65 9 * revision 1.0 20-Oct-2013 1st release, Does not support interrupts.
nyamfg 0:3fd57444bc65 10 */
nyamfg 0:3fd57444bc65 11
nyamfg 0:3fd57444bc65 12 #ifndef LPS331_I2C_H
nyamfg 0:3fd57444bc65 13 #define LPS331_I2C_H
nyamfg 0:3fd57444bc65 14
nyamfg 0:3fd57444bc65 15 #include "mbed.h"
nyamfg 0:3fd57444bc65 16
nyamfg 0:3fd57444bc65 17 // SA0 status configuration values.
nyamfg 0:3fd57444bc65 18 #define LPS331_I2C_SA0_HIGH true
nyamfg 0:3fd57444bc65 19 #define LPS331_I2C_SA0_LOW false
nyamfg 0:3fd57444bc65 20
nyamfg 0:3fd57444bc65 21 // Pressure configuration values.
nyamfg 0:3fd57444bc65 22 #define LPS331_I2C_PRESSURE_AVG_1 0x00
nyamfg 0:3fd57444bc65 23 #define LPS331_I2C_PRESSURE_AVG_2 0x01
nyamfg 0:3fd57444bc65 24 #define LPS331_I2C_PRESSURE_AVG_4 0x02
nyamfg 0:3fd57444bc65 25 #define LPS331_I2C_PRESSURE_AVG_8 0x03
nyamfg 0:3fd57444bc65 26 #define LPS331_I2C_PRESSURE_AVG_16 0x04
nyamfg 0:3fd57444bc65 27 #define LPS331_I2C_PRESSURE_AVG_32 0x05
nyamfg 0:3fd57444bc65 28 #define LPS331_I2C_PRESSURE_AVG_64 0x06
nyamfg 0:3fd57444bc65 29 #define LPS331_I2C_PRESSURE_AVG_128 0x07
nyamfg 0:3fd57444bc65 30 #define LPS331_I2C_PRESSURE_AVG_256 0x08
nyamfg 0:3fd57444bc65 31 #define LPS331_I2C_PRESSURE_AVG_384 0x09
nyamfg 0:3fd57444bc65 32 #define LPS331_I2C_PRESSURE_AVG_512 0x0a
nyamfg 0:3fd57444bc65 33
nyamfg 0:3fd57444bc65 34 // Temperature configuration values.
nyamfg 0:3fd57444bc65 35 #define LPS331_I2C_TEMP_AVG_1 0x00
nyamfg 0:3fd57444bc65 36 #define LPS331_I2C_TEMP_AVG_2 0x01
nyamfg 0:3fd57444bc65 37 #define LPS331_I2C_TEMP_AVG_4 0x02
nyamfg 0:3fd57444bc65 38 #define LPS331_I2C_TEMP_AVG_8 0x03
nyamfg 0:3fd57444bc65 39 #define LPS331_I2C_TEMP_AVG_16 0x04
nyamfg 0:3fd57444bc65 40 #define LPS331_I2C_TEMP_AVG_32 0x05
nyamfg 0:3fd57444bc65 41 #define LPS331_I2C_TEMP_AVG_64 0x06
nyamfg 0:3fd57444bc65 42 #define LPS331_I2C_TEMP_AVG_128 0x07
nyamfg 0:3fd57444bc65 43
nyamfg 0:3fd57444bc65 44 // Data Rate Pressure / Temperature
nyamfg 0:3fd57444bc65 45 #define LPS331_I2C_DATARATE_ONESHOT 0x00 // OneShot OneShot
nyamfg 0:3fd57444bc65 46 #define LPS331_I2C_DATARATE_1HZ 0x01 // 1Hz 1Hz
nyamfg 0:3fd57444bc65 47 #define LPS331_I2C_DATARATE_7HZ 0x02 // 7Hz 1Hz
nyamfg 0:3fd57444bc65 48 #define LPS331_I2C_DATARATE_12_5HZ 0x03 // 12.5Hz 1Hz
nyamfg 0:3fd57444bc65 49 #define LPS331_I2C_DATARATE_25HZ 0x04 // 25Hz 1Hz
nyamfg 0:3fd57444bc65 50 #define LPS331_I2C_DATARATE_7HZ_T 0x05 // 7Hz 7Hz
nyamfg 0:3fd57444bc65 51 #define LPS331_I2C_DATARATE_12_5HZ_T 0x06 // 12.5Hz 12.5Hz
nyamfg 0:3fd57444bc65 52 #define LPS331_I2C_DATARATE_25HZ_T 0x07 // 25Hz 25Hz (*)
nyamfg 0:3fd57444bc65 53 // (*) Not allowed with PRESSURE_AVG_512 & TEMP_AVG_128.
nyamfg 0:3fd57444bc65 54 // More information , see datasheet.
nyamfg 0:3fd57444bc65 55
nyamfg 0:3fd57444bc65 56 // I2C Address.
nyamfg 0:3fd57444bc65 57 #define LPS331_I2C_ADDRESS_SA0_HIGH 0xba
nyamfg 0:3fd57444bc65 58 #define LPS331_I2C_ADDRESS_SA0_LOW 0xb8
nyamfg 0:3fd57444bc65 59
nyamfg 0:3fd57444bc65 60 class LPS331_I2C
nyamfg 0:3fd57444bc65 61 {
nyamfg 0:3fd57444bc65 62 public:
nyamfg 0:3fd57444bc65 63 LPS331_I2C(PinName sda, PinName scl, bool sa0);
nyamfg 0:3fd57444bc65 64 ~LPS331_I2C();
nyamfg 0:3fd57444bc65 65
nyamfg 0:3fd57444bc65 66 char whoami();
nyamfg 0:3fd57444bc65 67 bool isAvailable();
nyamfg 0:3fd57444bc65 68
nyamfg 0:3fd57444bc65 69 void setResolution(char pressure_avg, char temp_avg);
nyamfg 0:3fd57444bc65 70 void setActive(bool is_active);
nyamfg 0:3fd57444bc65 71 void setDataRate(char datarate);
nyamfg 0:3fd57444bc65 72
nyamfg 0:3fd57444bc65 73 float getPressure();
nyamfg 0:3fd57444bc65 74 float getTemperature();
nyamfg 0:3fd57444bc65 75
nyamfg 0:3fd57444bc65 76 void _write(char subaddress, char data);
nyamfg 0:3fd57444bc65 77 char _read(char subaddress);
nyamfg 0:3fd57444bc65 78
nyamfg 0:3fd57444bc65 79 private:
nyamfg 0:3fd57444bc65 80 I2C _i2c;
nyamfg 0:3fd57444bc65 81 char _address;
nyamfg 0:3fd57444bc65 82 char _ctrlreg1;
nyamfg 0:3fd57444bc65 83 };
nyamfg 0:3fd57444bc65 84
nyamfg 0:3fd57444bc65 85
nyamfg 0:3fd57444bc65 86 #endif /* LPC331_I2C_H */
nyamfg 0:3fd57444bc65 87