SCP1000 Library
Dependents: SCP1000Example 0sample_SCP1000_USB SCP1000_Fastsensing
SCP1000.h
00001 /* 00002 Copyright (c) 2011, Senio Networks, Inc. 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 00023 #ifndef SCP1000_H 00024 #define SCP1000_H 00025 00026 #include "mbed.h" 00027 00028 /** 00029 * SCP1000 pressure/temperature sensor 00030 */ 00031 class SCP1000 { 00032 public: 00033 00034 /***/ 00035 enum OperationMode { 00036 CANCEL = 0x00, 00037 HIGH_SPEED_MODE = 0x09, 00038 HIGH_RESOLUTION_MODE = 0x0A, 00039 ULTRA_LOW_POWER_MODE = 0x0B, 00040 LOW_POWER = 0x0C, 00041 SELF_TEST = 0x0F, 00042 }; 00043 00044 /** 00045 * creates an SCP1000 interface with specified pins 00046 * 00047 * @param PinName mosi SPI MOSI pin 00048 * @param PinName miso SPI MISO pin 00049 * @param PinName sclk SPI SCLK pin 00050 * @param PinName cs SPI CS pin 00051 * @param OperationMode mode Initial operation mode 00052 */ 00053 SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs, OperationMode mode = HIGH_RESOLUTION_MODE); 00054 00055 ~SCP1000() {}; 00056 00057 /** 00058 * reads the revision number 00059 * 00060 * @returns revision number 00061 */ 00062 int revision(); 00063 00064 /** 00065 * checks if data is ready 00066 * 00067 * @returns true if data is ready, false otherwise 00068 */ 00069 bool isReady(); 00070 00071 /** 00072 * performs software reset 00073 */ 00074 void reset(); 00075 00076 /** 00077 * sets the operation mode 00078 */ 00079 void setOperationMode(OperationMode mode); 00080 00081 /** 00082 * performs self test 00083 * 00084 * @returns the result of the test (true if succeeded, false otherwise) 00085 */ 00086 bool performSelfTest(); 00087 00088 /** 00089 * reads the current pressure 00090 * 00091 * @param waitForDataReady if true, it will wait until data becomes ready 00092 * 00093 * @returns pressure in hectopascal (hPa) 00094 */ 00095 float readPressure(bool waitForDataReady = true); 00096 00097 /** 00098 * reads the current temperature 00099 * 00100 * @param waitForDataReady if true, it will wait until data becomes ready 00101 * 00102 * @returns temperature in Celsius 00103 */ 00104 float readTemperature(bool waitForDataReady = true); 00105 00106 private: 00107 enum RegisterName { 00108 REVID = 0x00, // ASIC revision number 00109 OPERATION = 0x03, // Operation register 00110 OPSTATUS = 0x04, // Operation status 00111 RSTR = 0x06, // ASIC software reset 00112 STATUS = 0x07, // ASIC top-level status 00113 DATARD8 = 0x1F, // Pressure output data (MSB) 00114 DATARD16 = 0x20, // Pressure output data (LSB, 16 bits) 00115 TEMPOUT = 0x21, // Temperature output data (16 bits) 00116 }; 00117 00118 enum Command { 00119 READ = 0x00, // SCP1000 READ command 00120 WRITE = 0x02, // SCP1000 WRITE command 00121 }; 00122 00123 SPI spi; 00124 DigitalOut selectPin; 00125 00126 int readRegister(RegisterName registerName, bool twoBytes = 0); 00127 void writeRegister(RegisterName registerName, char value); 00128 }; 00129 00130 #endif
Generated on Thu Jul 14 2022 10:09:38 by 1.7.2