STMicroelectronics LPS331 I2C Library.

Dependents:   LPS331_HelloWorld mbed_vfd_thermometer

Committer:
nyamfg
Date:
Mon Oct 21 16:39:58 2013 +0000
Revision:
1:b7d3d6e82049
Parent:
0:3fd57444bc65
I2C performance improvements.

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 1:b7d3d6e82049 9 * revision 1.1 22-Oct-2013 Add multibyte read, Change temperature and pressure reading method.
nyamfg 0:3fd57444bc65 10 * revision 1.0 20-Oct-2013 1st release, Does not support interrupts.
nyamfg 0:3fd57444bc65 11 */
nyamfg 0:3fd57444bc65 12
nyamfg 0:3fd57444bc65 13 #ifndef LPS331_I2C_H
nyamfg 0:3fd57444bc65 14 #define LPS331_I2C_H
nyamfg 0:3fd57444bc65 15
nyamfg 0:3fd57444bc65 16 #include "mbed.h"
nyamfg 0:3fd57444bc65 17
nyamfg 0:3fd57444bc65 18 // SA0 status configuration values.
nyamfg 0:3fd57444bc65 19 #define LPS331_I2C_SA0_HIGH true
nyamfg 0:3fd57444bc65 20 #define LPS331_I2C_SA0_LOW false
nyamfg 0:3fd57444bc65 21
nyamfg 0:3fd57444bc65 22 // Pressure configuration values.
nyamfg 0:3fd57444bc65 23 #define LPS331_I2C_PRESSURE_AVG_1 0x00
nyamfg 0:3fd57444bc65 24 #define LPS331_I2C_PRESSURE_AVG_2 0x01
nyamfg 0:3fd57444bc65 25 #define LPS331_I2C_PRESSURE_AVG_4 0x02
nyamfg 0:3fd57444bc65 26 #define LPS331_I2C_PRESSURE_AVG_8 0x03
nyamfg 0:3fd57444bc65 27 #define LPS331_I2C_PRESSURE_AVG_16 0x04
nyamfg 0:3fd57444bc65 28 #define LPS331_I2C_PRESSURE_AVG_32 0x05
nyamfg 0:3fd57444bc65 29 #define LPS331_I2C_PRESSURE_AVG_64 0x06
nyamfg 0:3fd57444bc65 30 #define LPS331_I2C_PRESSURE_AVG_128 0x07
nyamfg 0:3fd57444bc65 31 #define LPS331_I2C_PRESSURE_AVG_256 0x08
nyamfg 0:3fd57444bc65 32 #define LPS331_I2C_PRESSURE_AVG_384 0x09
nyamfg 0:3fd57444bc65 33 #define LPS331_I2C_PRESSURE_AVG_512 0x0a
nyamfg 0:3fd57444bc65 34
nyamfg 0:3fd57444bc65 35 // Temperature configuration values.
nyamfg 0:3fd57444bc65 36 #define LPS331_I2C_TEMP_AVG_1 0x00
nyamfg 0:3fd57444bc65 37 #define LPS331_I2C_TEMP_AVG_2 0x01
nyamfg 0:3fd57444bc65 38 #define LPS331_I2C_TEMP_AVG_4 0x02
nyamfg 0:3fd57444bc65 39 #define LPS331_I2C_TEMP_AVG_8 0x03
nyamfg 0:3fd57444bc65 40 #define LPS331_I2C_TEMP_AVG_16 0x04
nyamfg 0:3fd57444bc65 41 #define LPS331_I2C_TEMP_AVG_32 0x05
nyamfg 0:3fd57444bc65 42 #define LPS331_I2C_TEMP_AVG_64 0x06
nyamfg 0:3fd57444bc65 43 #define LPS331_I2C_TEMP_AVG_128 0x07
nyamfg 0:3fd57444bc65 44
nyamfg 0:3fd57444bc65 45 // Data Rate Pressure / Temperature
nyamfg 0:3fd57444bc65 46 #define LPS331_I2C_DATARATE_ONESHOT 0x00 // OneShot OneShot
nyamfg 0:3fd57444bc65 47 #define LPS331_I2C_DATARATE_1HZ 0x01 // 1Hz 1Hz
nyamfg 0:3fd57444bc65 48 #define LPS331_I2C_DATARATE_7HZ 0x02 // 7Hz 1Hz
nyamfg 0:3fd57444bc65 49 #define LPS331_I2C_DATARATE_12_5HZ 0x03 // 12.5Hz 1Hz
nyamfg 0:3fd57444bc65 50 #define LPS331_I2C_DATARATE_25HZ 0x04 // 25Hz 1Hz
nyamfg 0:3fd57444bc65 51 #define LPS331_I2C_DATARATE_7HZ_T 0x05 // 7Hz 7Hz
nyamfg 0:3fd57444bc65 52 #define LPS331_I2C_DATARATE_12_5HZ_T 0x06 // 12.5Hz 12.5Hz
nyamfg 0:3fd57444bc65 53 #define LPS331_I2C_DATARATE_25HZ_T 0x07 // 25Hz 25Hz (*)
nyamfg 0:3fd57444bc65 54 // (*) Not allowed with PRESSURE_AVG_512 & TEMP_AVG_128.
nyamfg 0:3fd57444bc65 55 // More information , see datasheet.
nyamfg 0:3fd57444bc65 56
nyamfg 0:3fd57444bc65 57 // I2C Address.
nyamfg 0:3fd57444bc65 58 #define LPS331_I2C_ADDRESS_SA0_HIGH 0xba
nyamfg 0:3fd57444bc65 59 #define LPS331_I2C_ADDRESS_SA0_LOW 0xb8
nyamfg 0:3fd57444bc65 60
nyamfg 0:3fd57444bc65 61 class LPS331_I2C
nyamfg 0:3fd57444bc65 62 {
nyamfg 0:3fd57444bc65 63 public:
nyamfg 0:3fd57444bc65 64 LPS331_I2C(PinName sda, PinName scl, bool sa0);
nyamfg 0:3fd57444bc65 65 ~LPS331_I2C();
nyamfg 0:3fd57444bc65 66
nyamfg 0:3fd57444bc65 67 char whoami();
nyamfg 0:3fd57444bc65 68 bool isAvailable();
nyamfg 0:3fd57444bc65 69
nyamfg 0:3fd57444bc65 70 void setResolution(char pressure_avg, char temp_avg);
nyamfg 0:3fd57444bc65 71 void setActive(bool is_active);
nyamfg 0:3fd57444bc65 72 void setDataRate(char datarate);
nyamfg 0:3fd57444bc65 73
nyamfg 0:3fd57444bc65 74 float getPressure();
nyamfg 0:3fd57444bc65 75 float getTemperature();
nyamfg 0:3fd57444bc65 76
nyamfg 0:3fd57444bc65 77 void _write(char subaddress, char data);
nyamfg 0:3fd57444bc65 78 char _read(char subaddress);
nyamfg 1:b7d3d6e82049 79 void _read_multibyte(char startsubaddress, char* data, char count);
nyamfg 0:3fd57444bc65 80
nyamfg 0:3fd57444bc65 81 private:
nyamfg 0:3fd57444bc65 82 I2C _i2c;
nyamfg 0:3fd57444bc65 83 char _address;
nyamfg 0:3fd57444bc65 84 char _ctrlreg1;
nyamfg 0:3fd57444bc65 85 };
nyamfg 0:3fd57444bc65 86
nyamfg 0:3fd57444bc65 87
nyamfg 0:3fd57444bc65 88 #endif /* LPC331_I2C_H */
nyamfg 0:3fd57444bc65 89