STMicroelectronics LPS331AP, LPS25H SPI Library. This library is base on https://developer.mbed.org/users/nyamfg/code/LPS331_I2C/
Dependents: LPS331_SPI_Test main_SPC
Fork of LPS331_I2C by
LPS331_SPI.h@3:5a56dd5131bb, 2016-07-28 (annotated)
- Committer:
- ohtsuka
- Date:
- Thu Jul 28 09:28:02 2016 +0000
- Revision:
- 3:5a56dd5131bb
- Parent:
- 2:c2aa9cfc45c2
- Child:
- 4:af2153bce185
replace string "I2C" to "SPI", and add credit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyamfg | 0:3fd57444bc65 | 1 | /* |
ohtsuka | 3:5a56dd5131bb | 2 | * I2C/SPI digital pressure sensor "LPS331AP" library for SPI 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 | * |
ohtsuka | 3:5a56dd5131bb | 6 | * Copyright(c) -2016 Toru OHTSUKA, |
nyamfg | 0:3fd57444bc65 | 7 | * Copyright(c) -2013 unos@NYAMFG, |
nyamfg | 0:3fd57444bc65 | 8 | * Released under the MIT License: http://mbed.org/license/mit |
nyamfg | 0:3fd57444bc65 | 9 | * |
nyamfg | 1:b7d3d6e82049 | 10 | * revision 1.1 22-Oct-2013 Add multibyte read, Change temperature and pressure reading method. |
nyamfg | 0:3fd57444bc65 | 11 | * revision 1.0 20-Oct-2013 1st release, Does not support interrupts. |
nyamfg | 0:3fd57444bc65 | 12 | */ |
nyamfg | 0:3fd57444bc65 | 13 | |
ohtsuka | 3:5a56dd5131bb | 14 | #ifndef LPS331_SPI_H |
ohtsuka | 3:5a56dd5131bb | 15 | #define LPS331_SPI_H |
nyamfg | 0:3fd57444bc65 | 16 | |
nyamfg | 0:3fd57444bc65 | 17 | #include "mbed.h" |
nyamfg | 0:3fd57444bc65 | 18 | |
nyamfg | 0:3fd57444bc65 | 19 | // SA0 status configuration values. |
ohtsuka | 3:5a56dd5131bb | 20 | #define LPS331_SPI_SA0_HIGH true |
ohtsuka | 3:5a56dd5131bb | 21 | #define LPS331_SPI_SA0_LOW false |
nyamfg | 0:3fd57444bc65 | 22 | |
nyamfg | 0:3fd57444bc65 | 23 | // Pressure configuration values. |
ohtsuka | 3:5a56dd5131bb | 24 | #define LPS331_SPI_PRESSURE_AVG_1 0x00 |
ohtsuka | 3:5a56dd5131bb | 25 | #define LPS331_SPI_PRESSURE_AVG_2 0x01 |
ohtsuka | 3:5a56dd5131bb | 26 | #define LPS331_SPI_PRESSURE_AVG_4 0x02 |
ohtsuka | 3:5a56dd5131bb | 27 | #define LPS331_SPI_PRESSURE_AVG_8 0x03 |
ohtsuka | 3:5a56dd5131bb | 28 | #define LPS331_SPI_PRESSURE_AVG_16 0x04 |
ohtsuka | 3:5a56dd5131bb | 29 | #define LPS331_SPI_PRESSURE_AVG_32 0x05 |
ohtsuka | 3:5a56dd5131bb | 30 | #define LPS331_SPI_PRESSURE_AVG_64 0x06 |
ohtsuka | 3:5a56dd5131bb | 31 | #define LPS331_SPI_PRESSURE_AVG_128 0x07 |
ohtsuka | 3:5a56dd5131bb | 32 | #define LPS331_SPI_PRESSURE_AVG_256 0x08 |
ohtsuka | 3:5a56dd5131bb | 33 | #define LPS331_SPI_PRESSURE_AVG_384 0x09 |
ohtsuka | 3:5a56dd5131bb | 34 | #define LPS331_SPI_PRESSURE_AVG_512 0x0a |
nyamfg | 0:3fd57444bc65 | 35 | |
nyamfg | 0:3fd57444bc65 | 36 | // Temperature configuration values. |
ohtsuka | 3:5a56dd5131bb | 37 | #define LPS331_SPI_TEMP_AVG_1 0x00 |
ohtsuka | 3:5a56dd5131bb | 38 | #define LPS331_SPI_TEMP_AVG_2 0x01 |
ohtsuka | 3:5a56dd5131bb | 39 | #define LPS331_SPI_TEMP_AVG_4 0x02 |
ohtsuka | 3:5a56dd5131bb | 40 | #define LPS331_SPI_TEMP_AVG_8 0x03 |
ohtsuka | 3:5a56dd5131bb | 41 | #define LPS331_SPI_TEMP_AVG_16 0x04 |
ohtsuka | 3:5a56dd5131bb | 42 | #define LPS331_SPI_TEMP_AVG_32 0x05 |
ohtsuka | 3:5a56dd5131bb | 43 | #define LPS331_SPI_TEMP_AVG_64 0x06 |
ohtsuka | 3:5a56dd5131bb | 44 | #define LPS331_SPI_TEMP_AVG_128 0x07 |
nyamfg | 0:3fd57444bc65 | 45 | |
nyamfg | 0:3fd57444bc65 | 46 | // Data Rate Pressure / Temperature |
ohtsuka | 3:5a56dd5131bb | 47 | #define LPS331_SPI_DATARATE_ONESHOT 0x00 // OneShot OneShot |
ohtsuka | 3:5a56dd5131bb | 48 | #define LPS331_SPI_DATARATE_1HZ 0x01 // 1Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 49 | #define LPS331_SPI_DATARATE_7HZ 0x02 // 7Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 50 | #define LPS331_SPI_DATARATE_12_5HZ 0x03 // 12.5Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 51 | #define LPS331_SPI_DATARATE_25HZ 0x04 // 25Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 52 | #define LPS331_SPI_DATARATE_7HZ_T 0x05 // 7Hz 7Hz |
ohtsuka | 3:5a56dd5131bb | 53 | #define LPS331_SPI_DATARATE_12_5HZ_T 0x06 // 12.5Hz 12.5Hz |
ohtsuka | 3:5a56dd5131bb | 54 | #define LPS331_SPI_DATARATE_25HZ_T 0x07 // 25Hz 25Hz (*) |
nyamfg | 0:3fd57444bc65 | 55 | // (*) Not allowed with PRESSURE_AVG_512 & TEMP_AVG_128. |
nyamfg | 0:3fd57444bc65 | 56 | // More information , see datasheet. |
nyamfg | 0:3fd57444bc65 | 57 | |
nyamfg | 0:3fd57444bc65 | 58 | // I2C Address. |
ohtsuka | 3:5a56dd5131bb | 59 | #define LPS331_SPI_ADDRESS_SA0_HIGH 0xba |
ohtsuka | 3:5a56dd5131bb | 60 | #define LPS331_SPI_ADDRESS_SA0_LOW 0xb8 |
nyamfg | 0:3fd57444bc65 | 61 | |
ohtsuka | 3:5a56dd5131bb | 62 | class LPS331_SPI |
nyamfg | 0:3fd57444bc65 | 63 | { |
nyamfg | 0:3fd57444bc65 | 64 | public: |
ohtsuka | 3:5a56dd5131bb | 65 | LPS331_SPI(PinName sda, PinName scl, bool sa0); |
ohtsuka | 3:5a56dd5131bb | 66 | ~LPS331_SPI(); |
nyamfg | 0:3fd57444bc65 | 67 | |
nyamfg | 0:3fd57444bc65 | 68 | char whoami(); |
nyamfg | 0:3fd57444bc65 | 69 | bool isAvailable(); |
nyamfg | 0:3fd57444bc65 | 70 | |
nyamfg | 0:3fd57444bc65 | 71 | void setResolution(char pressure_avg, char temp_avg); |
nyamfg | 0:3fd57444bc65 | 72 | void setActive(bool is_active); |
nyamfg | 0:3fd57444bc65 | 73 | void setDataRate(char datarate); |
nyamfg | 0:3fd57444bc65 | 74 | |
nyamfg | 0:3fd57444bc65 | 75 | float getPressure(); |
nyamfg | 0:3fd57444bc65 | 76 | float getTemperature(); |
nyamfg | 0:3fd57444bc65 | 77 | |
nyamfg | 0:3fd57444bc65 | 78 | void _write(char subaddress, char data); |
nyamfg | 0:3fd57444bc65 | 79 | char _read(char subaddress); |
nyamfg | 1:b7d3d6e82049 | 80 | void _read_multibyte(char startsubaddress, char* data, char count); |
nyamfg | 0:3fd57444bc65 | 81 | |
nyamfg | 0:3fd57444bc65 | 82 | private: |
nyamfg | 0:3fd57444bc65 | 83 | I2C _i2c; |
nyamfg | 0:3fd57444bc65 | 84 | char _address; |
nyamfg | 0:3fd57444bc65 | 85 | char _ctrlreg1; |
nyamfg | 0:3fd57444bc65 | 86 | }; |
nyamfg | 0:3fd57444bc65 | 87 | |
nyamfg | 0:3fd57444bc65 | 88 | |
ohtsuka | 3:5a56dd5131bb | 89 | #endif /* LPC331_SPI_H */ |
nyamfg | 0:3fd57444bc65 | 90 |