SCP1000 Library
Dependents: SCP1000Example 0sample_SCP1000_USB SCP1000_Fastsensing
SCP1000.h@5:62872ee396a8, 2011-02-08 (annotated)
- Committer:
- yamaguch
- Date:
- Tue Feb 08 07:31:09 2011 +0000
- Revision:
- 5:62872ee396a8
- Child:
- 6:d9489d50669d
0.95
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 5:62872ee396a8 | 1 | #ifndef SCP1000_H |
yamaguch | 5:62872ee396a8 | 2 | #define SCP1000_H |
yamaguch | 5:62872ee396a8 | 3 | |
yamaguch | 5:62872ee396a8 | 4 | #include "mbed.h" |
yamaguch | 5:62872ee396a8 | 5 | |
yamaguch | 5:62872ee396a8 | 6 | /** |
yamaguch | 5:62872ee396a8 | 7 | * SCP1000 pressure/temperature sensor |
yamaguch | 5:62872ee396a8 | 8 | */ |
yamaguch | 5:62872ee396a8 | 9 | |
yamaguch | 5:62872ee396a8 | 10 | class SCP1000 { |
yamaguch | 5:62872ee396a8 | 11 | public: |
yamaguch | 5:62872ee396a8 | 12 | enum OperationMode { |
yamaguch | 5:62872ee396a8 | 13 | CANCEL = 0x00, |
yamaguch | 5:62872ee396a8 | 14 | HIGH_SPEED_MODE = 0x09, |
yamaguch | 5:62872ee396a8 | 15 | HIGH_RESOLUTION_MODE = 0x0A, |
yamaguch | 5:62872ee396a8 | 16 | ULTRA_LOW_POWER_MODE = 0x0B, |
yamaguch | 5:62872ee396a8 | 17 | LOW_POWER = 0x0C, |
yamaguch | 5:62872ee396a8 | 18 | SELF_TEST = 0x0F, |
yamaguch | 5:62872ee396a8 | 19 | }; |
yamaguch | 5:62872ee396a8 | 20 | |
yamaguch | 5:62872ee396a8 | 21 | /** |
yamaguch | 5:62872ee396a8 | 22 | * creates an SCP1000 interface with specified pins |
yamaguch | 5:62872ee396a8 | 23 | * |
yamaguch | 5:62872ee396a8 | 24 | * @param PinName mosi SPI MOSI pin |
yamaguch | 5:62872ee396a8 | 25 | * @param PinName miso SPI MISO pin |
yamaguch | 5:62872ee396a8 | 26 | * @param PinName sclk SPI SCLK pin |
yamaguch | 5:62872ee396a8 | 27 | * @param PinName cs SPI CS pin |
yamaguch | 5:62872ee396a8 | 28 | * @param OperationMode mode Initial operation mode |
yamaguch | 5:62872ee396a8 | 29 | */ |
yamaguch | 5:62872ee396a8 | 30 | SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs, OperationMode mode = HIGH_RESOLUTION_MODE); |
yamaguch | 5:62872ee396a8 | 31 | |
yamaguch | 5:62872ee396a8 | 32 | ~SCP1000() {}; |
yamaguch | 5:62872ee396a8 | 33 | |
yamaguch | 5:62872ee396a8 | 34 | /** |
yamaguch | 5:62872ee396a8 | 35 | * reads revision number |
yamaguch | 5:62872ee396a8 | 36 | * |
yamaguch | 5:62872ee396a8 | 37 | * @returns revision number |
yamaguch | 5:62872ee396a8 | 38 | */ |
yamaguch | 5:62872ee396a8 | 39 | int revision(); |
yamaguch | 5:62872ee396a8 | 40 | |
yamaguch | 5:62872ee396a8 | 41 | /** |
yamaguch | 5:62872ee396a8 | 42 | * checks if data is ready |
yamaguch | 5:62872ee396a8 | 43 | * |
yamaguch | 5:62872ee396a8 | 44 | * @returns true if data is ready, false otherwise |
yamaguch | 5:62872ee396a8 | 45 | */ |
yamaguch | 5:62872ee396a8 | 46 | bool isReady(); |
yamaguch | 5:62872ee396a8 | 47 | |
yamaguch | 5:62872ee396a8 | 48 | /** |
yamaguch | 5:62872ee396a8 | 49 | * performs software reset |
yamaguch | 5:62872ee396a8 | 50 | */ |
yamaguch | 5:62872ee396a8 | 51 | void reset(); |
yamaguch | 5:62872ee396a8 | 52 | |
yamaguch | 5:62872ee396a8 | 53 | /** |
yamaguch | 5:62872ee396a8 | 54 | * sets the operation mode |
yamaguch | 5:62872ee396a8 | 55 | */ |
yamaguch | 5:62872ee396a8 | 56 | void setOperationMode(OperationMode mode); |
yamaguch | 5:62872ee396a8 | 57 | |
yamaguch | 5:62872ee396a8 | 58 | /** |
yamaguch | 5:62872ee396a8 | 59 | * performs self test |
yamaguch | 5:62872ee396a8 | 60 | * |
yamaguch | 5:62872ee396a8 | 61 | * @returns the result of the test (true if succeeded, false otherwise) |
yamaguch | 5:62872ee396a8 | 62 | */ |
yamaguch | 5:62872ee396a8 | 63 | bool performSelfTest(); |
yamaguch | 5:62872ee396a8 | 64 | |
yamaguch | 5:62872ee396a8 | 65 | /** |
yamaguch | 5:62872ee396a8 | 66 | * reads the current pressure |
yamaguch | 5:62872ee396a8 | 67 | * |
yamaguch | 5:62872ee396a8 | 68 | * @param waitForDataReady if true, it will wait until data becomes ready to read |
yamaguch | 5:62872ee396a8 | 69 | * |
yamaguch | 5:62872ee396a8 | 70 | * @returns pressure in hectopascal (hPa) |
yamaguch | 5:62872ee396a8 | 71 | */ |
yamaguch | 5:62872ee396a8 | 72 | float readPressure(bool waitForDataReady = false); |
yamaguch | 5:62872ee396a8 | 73 | |
yamaguch | 5:62872ee396a8 | 74 | /** |
yamaguch | 5:62872ee396a8 | 75 | * reads the current temperature |
yamaguch | 5:62872ee396a8 | 76 | * |
yamaguch | 5:62872ee396a8 | 77 | * @param waitForDataReady if true, it will wait until data becomes ready to read |
yamaguch | 5:62872ee396a8 | 78 | * |
yamaguch | 5:62872ee396a8 | 79 | * @returns temperature in Celsius |
yamaguch | 5:62872ee396a8 | 80 | */ |
yamaguch | 5:62872ee396a8 | 81 | float readTemperature(bool waitForDataReady = false); |
yamaguch | 5:62872ee396a8 | 82 | |
yamaguch | 5:62872ee396a8 | 83 | private: |
yamaguch | 5:62872ee396a8 | 84 | enum RegisterName { |
yamaguch | 5:62872ee396a8 | 85 | REVID = 0x00, // ASIC revision number |
yamaguch | 5:62872ee396a8 | 86 | OPERATION = 0x03, // Operation register |
yamaguch | 5:62872ee396a8 | 87 | OPSTATUS = 0x04, // Operation status |
yamaguch | 5:62872ee396a8 | 88 | RSTR = 0x06, // ASIC software reset |
yamaguch | 5:62872ee396a8 | 89 | STATUS = 0x07, // ASIC top-level status |
yamaguch | 5:62872ee396a8 | 90 | DATARD8 = 0x1F, // Pressure output data (MSB) |
yamaguch | 5:62872ee396a8 | 91 | DATARD16 = 0x20, // Pressure output data (LSB, 16 bits) |
yamaguch | 5:62872ee396a8 | 92 | TEMPOUT = 0x21, // Temperature output data (16 bits) |
yamaguch | 5:62872ee396a8 | 93 | }; |
yamaguch | 5:62872ee396a8 | 94 | |
yamaguch | 5:62872ee396a8 | 95 | enum Command { |
yamaguch | 5:62872ee396a8 | 96 | READ = 0x00, // SCP1000 READ command |
yamaguch | 5:62872ee396a8 | 97 | WRITE = 0x02, // SCP1000 WRITE command |
yamaguch | 5:62872ee396a8 | 98 | }; |
yamaguch | 5:62872ee396a8 | 99 | |
yamaguch | 5:62872ee396a8 | 100 | SPI spi; |
yamaguch | 5:62872ee396a8 | 101 | DigitalOut selectPin; |
yamaguch | 5:62872ee396a8 | 102 | |
yamaguch | 5:62872ee396a8 | 103 | int readRegister(RegisterName registerName, bool twoBytes = 0); |
yamaguch | 5:62872ee396a8 | 104 | void writeRegister(RegisterName registerName, char value); |
yamaguch | 5:62872ee396a8 | 105 | }; |
yamaguch | 5:62872ee396a8 | 106 | |
yamaguch | 5:62872ee396a8 | 107 | #endif |