SCP1000 Library
Dependents: SCP1000Example 0sample_SCP1000_USB SCP1000_Fastsensing
SCP1000.h@14:6ffff12eb3fc, 2011-10-31 (annotated)
- Committer:
- yamaguch
- Date:
- Mon Oct 31 10:55:15 2011 +0000
- Revision:
- 14:6ffff12eb3fc
- Parent:
- 12:b08cf651abe2
fixed a bug in performSelfTest()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 10:11a40ecf2361 | 1 | /* |
yamaguch | 10:11a40ecf2361 | 2 | Copyright (c) 2011, Senio Networks, Inc. |
yamaguch | 10:11a40ecf2361 | 3 | |
yamaguch | 10:11a40ecf2361 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
yamaguch | 10:11a40ecf2361 | 5 | of this software and associated documentation files (the "Software"), to deal |
yamaguch | 10:11a40ecf2361 | 6 | in the Software without restriction, including without limitation the rights |
yamaguch | 10:11a40ecf2361 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yamaguch | 10:11a40ecf2361 | 8 | copies of the Software, and to permit persons to whom the Software is |
yamaguch | 10:11a40ecf2361 | 9 | furnished to do so, subject to the following conditions: |
yamaguch | 10:11a40ecf2361 | 10 | |
yamaguch | 10:11a40ecf2361 | 11 | The above copyright notice and this permission notice shall be included in |
yamaguch | 10:11a40ecf2361 | 12 | all copies or substantial portions of the Software. |
yamaguch | 10:11a40ecf2361 | 13 | |
yamaguch | 10:11a40ecf2361 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yamaguch | 10:11a40ecf2361 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yamaguch | 10:11a40ecf2361 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yamaguch | 10:11a40ecf2361 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yamaguch | 10:11a40ecf2361 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yamaguch | 10:11a40ecf2361 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
yamaguch | 10:11a40ecf2361 | 20 | THE SOFTWARE. |
yamaguch | 10:11a40ecf2361 | 21 | */ |
yamaguch | 10:11a40ecf2361 | 22 | |
yamaguch | 5:62872ee396a8 | 23 | #ifndef SCP1000_H |
yamaguch | 5:62872ee396a8 | 24 | #define SCP1000_H |
yamaguch | 5:62872ee396a8 | 25 | |
yamaguch | 5:62872ee396a8 | 26 | #include "mbed.h" |
yamaguch | 5:62872ee396a8 | 27 | |
yamaguch | 5:62872ee396a8 | 28 | /** |
yamaguch | 5:62872ee396a8 | 29 | * SCP1000 pressure/temperature sensor |
yamaguch | 5:62872ee396a8 | 30 | */ |
yamaguch | 5:62872ee396a8 | 31 | class SCP1000 { |
yamaguch | 5:62872ee396a8 | 32 | public: |
yamaguch | 12:b08cf651abe2 | 33 | |
yamaguch | 12:b08cf651abe2 | 34 | /***/ |
yamaguch | 12:b08cf651abe2 | 35 | enum OperationMode { |
yamaguch | 12:b08cf651abe2 | 36 | CANCEL = 0x00, |
yamaguch | 12:b08cf651abe2 | 37 | HIGH_SPEED_MODE = 0x09, |
yamaguch | 12:b08cf651abe2 | 38 | HIGH_RESOLUTION_MODE = 0x0A, |
yamaguch | 12:b08cf651abe2 | 39 | ULTRA_LOW_POWER_MODE = 0x0B, |
yamaguch | 12:b08cf651abe2 | 40 | LOW_POWER = 0x0C, |
yamaguch | 12:b08cf651abe2 | 41 | SELF_TEST = 0x0F, |
yamaguch | 12:b08cf651abe2 | 42 | }; |
yamaguch | 11:8a5dc32887d2 | 43 | |
yamaguch | 11:8a5dc32887d2 | 44 | /** |
yamaguch | 11:8a5dc32887d2 | 45 | * creates an SCP1000 interface with specified pins |
yamaguch | 11:8a5dc32887d2 | 46 | * |
yamaguch | 11:8a5dc32887d2 | 47 | * @param PinName mosi SPI MOSI pin |
yamaguch | 11:8a5dc32887d2 | 48 | * @param PinName miso SPI MISO pin |
yamaguch | 11:8a5dc32887d2 | 49 | * @param PinName sclk SPI SCLK pin |
yamaguch | 11:8a5dc32887d2 | 50 | * @param PinName cs SPI CS pin |
yamaguch | 11:8a5dc32887d2 | 51 | * @param OperationMode mode Initial operation mode |
yamaguch | 11:8a5dc32887d2 | 52 | */ |
yamaguch | 11:8a5dc32887d2 | 53 | SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs, OperationMode mode = HIGH_RESOLUTION_MODE); |
yamaguch | 11:8a5dc32887d2 | 54 | |
yamaguch | 5:62872ee396a8 | 55 | ~SCP1000() {}; |
yamaguch | 5:62872ee396a8 | 56 | |
yamaguch | 5:62872ee396a8 | 57 | /** |
yamaguch | 6:d9489d50669d | 58 | * reads the revision number |
yamaguch | 5:62872ee396a8 | 59 | * |
yamaguch | 5:62872ee396a8 | 60 | * @returns revision number |
yamaguch | 5:62872ee396a8 | 61 | */ |
yamaguch | 5:62872ee396a8 | 62 | int revision(); |
yamaguch | 5:62872ee396a8 | 63 | |
yamaguch | 5:62872ee396a8 | 64 | /** |
yamaguch | 5:62872ee396a8 | 65 | * checks if data is ready |
yamaguch | 5:62872ee396a8 | 66 | * |
yamaguch | 5:62872ee396a8 | 67 | * @returns true if data is ready, false otherwise |
yamaguch | 5:62872ee396a8 | 68 | */ |
yamaguch | 5:62872ee396a8 | 69 | bool isReady(); |
yamaguch | 5:62872ee396a8 | 70 | |
yamaguch | 5:62872ee396a8 | 71 | /** |
yamaguch | 5:62872ee396a8 | 72 | * performs software reset |
yamaguch | 5:62872ee396a8 | 73 | */ |
yamaguch | 5:62872ee396a8 | 74 | void reset(); |
yamaguch | 5:62872ee396a8 | 75 | |
yamaguch | 5:62872ee396a8 | 76 | /** |
yamaguch | 5:62872ee396a8 | 77 | * sets the operation mode |
yamaguch | 5:62872ee396a8 | 78 | */ |
yamaguch | 5:62872ee396a8 | 79 | void setOperationMode(OperationMode mode); |
yamaguch | 5:62872ee396a8 | 80 | |
yamaguch | 5:62872ee396a8 | 81 | /** |
yamaguch | 5:62872ee396a8 | 82 | * performs self test |
yamaguch | 5:62872ee396a8 | 83 | * |
yamaguch | 5:62872ee396a8 | 84 | * @returns the result of the test (true if succeeded, false otherwise) |
yamaguch | 5:62872ee396a8 | 85 | */ |
yamaguch | 5:62872ee396a8 | 86 | bool performSelfTest(); |
yamaguch | 5:62872ee396a8 | 87 | |
yamaguch | 5:62872ee396a8 | 88 | /** |
yamaguch | 5:62872ee396a8 | 89 | * reads the current pressure |
yamaguch | 5:62872ee396a8 | 90 | * |
yamaguch | 6:d9489d50669d | 91 | * @param waitForDataReady if true, it will wait until data becomes ready |
yamaguch | 5:62872ee396a8 | 92 | * |
yamaguch | 5:62872ee396a8 | 93 | * @returns pressure in hectopascal (hPa) |
yamaguch | 5:62872ee396a8 | 94 | */ |
yamaguch | 7:41606315d260 | 95 | float readPressure(bool waitForDataReady = true); |
yamaguch | 5:62872ee396a8 | 96 | |
yamaguch | 5:62872ee396a8 | 97 | /** |
yamaguch | 5:62872ee396a8 | 98 | * reads the current temperature |
yamaguch | 5:62872ee396a8 | 99 | * |
yamaguch | 6:d9489d50669d | 100 | * @param waitForDataReady if true, it will wait until data becomes ready |
yamaguch | 5:62872ee396a8 | 101 | * |
yamaguch | 5:62872ee396a8 | 102 | * @returns temperature in Celsius |
yamaguch | 5:62872ee396a8 | 103 | */ |
yamaguch | 7:41606315d260 | 104 | float readTemperature(bool waitForDataReady = true); |
yamaguch | 5:62872ee396a8 | 105 | |
yamaguch | 5:62872ee396a8 | 106 | private: |
yamaguch | 5:62872ee396a8 | 107 | enum RegisterName { |
yamaguch | 5:62872ee396a8 | 108 | REVID = 0x00, // ASIC revision number |
yamaguch | 5:62872ee396a8 | 109 | OPERATION = 0x03, // Operation register |
yamaguch | 5:62872ee396a8 | 110 | OPSTATUS = 0x04, // Operation status |
yamaguch | 5:62872ee396a8 | 111 | RSTR = 0x06, // ASIC software reset |
yamaguch | 5:62872ee396a8 | 112 | STATUS = 0x07, // ASIC top-level status |
yamaguch | 5:62872ee396a8 | 113 | DATARD8 = 0x1F, // Pressure output data (MSB) |
yamaguch | 5:62872ee396a8 | 114 | DATARD16 = 0x20, // Pressure output data (LSB, 16 bits) |
yamaguch | 5:62872ee396a8 | 115 | TEMPOUT = 0x21, // Temperature output data (16 bits) |
yamaguch | 5:62872ee396a8 | 116 | }; |
yamaguch | 5:62872ee396a8 | 117 | |
yamaguch | 5:62872ee396a8 | 118 | enum Command { |
yamaguch | 5:62872ee396a8 | 119 | READ = 0x00, // SCP1000 READ command |
yamaguch | 5:62872ee396a8 | 120 | WRITE = 0x02, // SCP1000 WRITE command |
yamaguch | 5:62872ee396a8 | 121 | }; |
yamaguch | 5:62872ee396a8 | 122 | |
yamaguch | 5:62872ee396a8 | 123 | SPI spi; |
yamaguch | 5:62872ee396a8 | 124 | DigitalOut selectPin; |
yamaguch | 5:62872ee396a8 | 125 | |
yamaguch | 5:62872ee396a8 | 126 | int readRegister(RegisterName registerName, bool twoBytes = 0); |
yamaguch | 5:62872ee396a8 | 127 | void writeRegister(RegisterName registerName, char value); |
yamaguch | 5:62872ee396a8 | 128 | }; |
yamaguch | 5:62872ee396a8 | 129 | |
yamaguch | 5:62872ee396a8 | 130 | #endif |