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@7:b74daa677551, 2016-07-28 (annotated)
- Committer:
- ohtsuka
- Date:
- Thu Jul 28 10:32:13 2016 +0000
- Revision:
- 7:b74daa677551
- Parent:
- 6:309af2a65bd6
add comment "support LPS25H"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyamfg | 0:3fd57444bc65 | 1 | /* |
ohtsuka | 7:b74daa677551 | 2 | * I2C/SPI digital pressure sensor "LPS331AP" "LPS25H" 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 | * |
ohtsuka | 4:af2153bce185 | 10 | * revision 1.2 07-Jul-2016 SPI version. |
nyamfg | 1:b7d3d6e82049 | 11 | * revision 1.1 22-Oct-2013 Add multibyte read, Change temperature and pressure reading method. |
nyamfg | 0:3fd57444bc65 | 12 | * revision 1.0 20-Oct-2013 1st release, Does not support interrupts. |
nyamfg | 0:3fd57444bc65 | 13 | */ |
nyamfg | 0:3fd57444bc65 | 14 | |
ohtsuka | 3:5a56dd5131bb | 15 | #ifndef LPS331_SPI_H |
ohtsuka | 3:5a56dd5131bb | 16 | #define LPS331_SPI_H |
nyamfg | 0:3fd57444bc65 | 17 | |
nyamfg | 0:3fd57444bc65 | 18 | #include "mbed.h" |
nyamfg | 0:3fd57444bc65 | 19 | |
nyamfg | 0:3fd57444bc65 | 20 | // SA0 status configuration values. |
ohtsuka | 3:5a56dd5131bb | 21 | #define LPS331_SPI_SA0_HIGH true |
ohtsuka | 3:5a56dd5131bb | 22 | #define LPS331_SPI_SA0_LOW false |
nyamfg | 0:3fd57444bc65 | 23 | |
nyamfg | 0:3fd57444bc65 | 24 | // Pressure configuration values. |
ohtsuka | 3:5a56dd5131bb | 25 | #define LPS331_SPI_PRESSURE_AVG_1 0x00 |
ohtsuka | 3:5a56dd5131bb | 26 | #define LPS331_SPI_PRESSURE_AVG_2 0x01 |
ohtsuka | 3:5a56dd5131bb | 27 | #define LPS331_SPI_PRESSURE_AVG_4 0x02 |
ohtsuka | 3:5a56dd5131bb | 28 | #define LPS331_SPI_PRESSURE_AVG_8 0x03 |
ohtsuka | 3:5a56dd5131bb | 29 | #define LPS331_SPI_PRESSURE_AVG_16 0x04 |
ohtsuka | 3:5a56dd5131bb | 30 | #define LPS331_SPI_PRESSURE_AVG_32 0x05 |
ohtsuka | 3:5a56dd5131bb | 31 | #define LPS331_SPI_PRESSURE_AVG_64 0x06 |
ohtsuka | 3:5a56dd5131bb | 32 | #define LPS331_SPI_PRESSURE_AVG_128 0x07 |
ohtsuka | 3:5a56dd5131bb | 33 | #define LPS331_SPI_PRESSURE_AVG_256 0x08 |
ohtsuka | 3:5a56dd5131bb | 34 | #define LPS331_SPI_PRESSURE_AVG_384 0x09 |
ohtsuka | 3:5a56dd5131bb | 35 | #define LPS331_SPI_PRESSURE_AVG_512 0x0a |
nyamfg | 0:3fd57444bc65 | 36 | |
nyamfg | 0:3fd57444bc65 | 37 | // Temperature configuration values. |
ohtsuka | 3:5a56dd5131bb | 38 | #define LPS331_SPI_TEMP_AVG_1 0x00 |
ohtsuka | 3:5a56dd5131bb | 39 | #define LPS331_SPI_TEMP_AVG_2 0x01 |
ohtsuka | 3:5a56dd5131bb | 40 | #define LPS331_SPI_TEMP_AVG_4 0x02 |
ohtsuka | 3:5a56dd5131bb | 41 | #define LPS331_SPI_TEMP_AVG_8 0x03 |
ohtsuka | 3:5a56dd5131bb | 42 | #define LPS331_SPI_TEMP_AVG_16 0x04 |
ohtsuka | 3:5a56dd5131bb | 43 | #define LPS331_SPI_TEMP_AVG_32 0x05 |
ohtsuka | 3:5a56dd5131bb | 44 | #define LPS331_SPI_TEMP_AVG_64 0x06 |
ohtsuka | 3:5a56dd5131bb | 45 | #define LPS331_SPI_TEMP_AVG_128 0x07 |
nyamfg | 0:3fd57444bc65 | 46 | |
nyamfg | 0:3fd57444bc65 | 47 | // Data Rate Pressure / Temperature |
ohtsuka | 3:5a56dd5131bb | 48 | #define LPS331_SPI_DATARATE_ONESHOT 0x00 // OneShot OneShot |
ohtsuka | 3:5a56dd5131bb | 49 | #define LPS331_SPI_DATARATE_1HZ 0x01 // 1Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 50 | #define LPS331_SPI_DATARATE_7HZ 0x02 // 7Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 51 | #define LPS331_SPI_DATARATE_12_5HZ 0x03 // 12.5Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 52 | #define LPS331_SPI_DATARATE_25HZ 0x04 // 25Hz 1Hz |
ohtsuka | 3:5a56dd5131bb | 53 | #define LPS331_SPI_DATARATE_7HZ_T 0x05 // 7Hz 7Hz |
ohtsuka | 3:5a56dd5131bb | 54 | #define LPS331_SPI_DATARATE_12_5HZ_T 0x06 // 12.5Hz 12.5Hz |
ohtsuka | 3:5a56dd5131bb | 55 | #define LPS331_SPI_DATARATE_25HZ_T 0x07 // 25Hz 25Hz (*) |
nyamfg | 0:3fd57444bc65 | 56 | // (*) Not allowed with PRESSURE_AVG_512 & TEMP_AVG_128. |
nyamfg | 0:3fd57444bc65 | 57 | // More information , see datasheet. |
nyamfg | 0:3fd57444bc65 | 58 | |
nyamfg | 0:3fd57444bc65 | 59 | // I2C Address. |
ohtsuka | 3:5a56dd5131bb | 60 | #define LPS331_SPI_ADDRESS_SA0_HIGH 0xba |
ohtsuka | 3:5a56dd5131bb | 61 | #define LPS331_SPI_ADDRESS_SA0_LOW 0xb8 |
nyamfg | 0:3fd57444bc65 | 62 | |
ohtsuka | 3:5a56dd5131bb | 63 | class LPS331_SPI |
nyamfg | 0:3fd57444bc65 | 64 | { |
nyamfg | 0:3fd57444bc65 | 65 | public: |
ohtsuka | 4:af2153bce185 | 66 | LPS331_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs); |
ohtsuka | 3:5a56dd5131bb | 67 | ~LPS331_SPI(); |
nyamfg | 0:3fd57444bc65 | 68 | |
nyamfg | 0:3fd57444bc65 | 69 | char whoami(); |
ohtsuka | 6:309af2a65bd6 | 70 | bool isLPS331(); |
ohtsuka | 6:309af2a65bd6 | 71 | bool isLPS25H(); |
nyamfg | 0:3fd57444bc65 | 72 | |
nyamfg | 0:3fd57444bc65 | 73 | void setResolution(char pressure_avg, char temp_avg); |
nyamfg | 0:3fd57444bc65 | 74 | void setActive(bool is_active); |
nyamfg | 0:3fd57444bc65 | 75 | void setDataRate(char datarate); |
nyamfg | 0:3fd57444bc65 | 76 | |
ohtsuka | 5:760a5e23dc62 | 77 | void quickStart(); |
ohtsuka | 5:760a5e23dc62 | 78 | |
nyamfg | 0:3fd57444bc65 | 79 | float getPressure(); |
nyamfg | 0:3fd57444bc65 | 80 | float getTemperature(); |
nyamfg | 0:3fd57444bc65 | 81 | |
nyamfg | 0:3fd57444bc65 | 82 | void _write(char subaddress, char data); |
nyamfg | 0:3fd57444bc65 | 83 | char _read(char subaddress); |
nyamfg | 1:b7d3d6e82049 | 84 | void _read_multibyte(char startsubaddress, char* data, char count); |
nyamfg | 0:3fd57444bc65 | 85 | |
nyamfg | 0:3fd57444bc65 | 86 | private: |
ohtsuka | 4:af2153bce185 | 87 | SPI _spi; |
ohtsuka | 4:af2153bce185 | 88 | DigitalOut _cs; |
nyamfg | 0:3fd57444bc65 | 89 | char _address; |
nyamfg | 0:3fd57444bc65 | 90 | char _ctrlreg1; |
nyamfg | 0:3fd57444bc65 | 91 | }; |
nyamfg | 0:3fd57444bc65 | 92 | |
nyamfg | 0:3fd57444bc65 | 93 | |
ohtsuka | 3:5a56dd5131bb | 94 | #endif /* LPC331_SPI_H */ |
nyamfg | 0:3fd57444bc65 | 95 |