SCP1000 Library

Dependents:   SCP1000Example 0sample_SCP1000_USB SCP1000_Fastsensing

Committer:
yamaguch
Date:
Fri Oct 28 09:23:18 2011 +0000
Revision:
10:11a40ecf2361
Parent:
9:422f7395f25e
Child:
11:8a5dc32887d2
0.92

Who changed what in which revision?

UserRevisionLine numberNew 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 8:654e88a4baf2 33 /***/
yamaguch 5:62872ee396a8 34 enum OperationMode {
yamaguch 5:62872ee396a8 35 CANCEL = 0x00,
yamaguch 5:62872ee396a8 36 HIGH_SPEED_MODE = 0x09,
yamaguch 5:62872ee396a8 37 HIGH_RESOLUTION_MODE = 0x0A,
yamaguch 5:62872ee396a8 38 ULTRA_LOW_POWER_MODE = 0x0B,
yamaguch 5:62872ee396a8 39 LOW_POWER = 0x0C,
yamaguch 5:62872ee396a8 40 SELF_TEST = 0x0F,
yamaguch 5:62872ee396a8 41 };
yamaguch 8:654e88a4baf2 42
yamaguch 5:62872ee396a8 43 /**
yamaguch 5:62872ee396a8 44 * creates an SCP1000 interface with specified pins
yamaguch 5:62872ee396a8 45 *
yamaguch 5:62872ee396a8 46 * @param PinName mosi SPI MOSI pin
yamaguch 5:62872ee396a8 47 * @param PinName miso SPI MISO pin
yamaguch 5:62872ee396a8 48 * @param PinName sclk SPI SCLK pin
yamaguch 5:62872ee396a8 49 * @param PinName cs SPI CS pin
yamaguch 5:62872ee396a8 50 * @param OperationMode mode Initial operation mode
yamaguch 5:62872ee396a8 51 */
yamaguch 5:62872ee396a8 52 SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs, OperationMode mode = HIGH_RESOLUTION_MODE);
yamaguch 5:62872ee396a8 53
yamaguch 5:62872ee396a8 54 ~SCP1000() {};
yamaguch 5:62872ee396a8 55
yamaguch 5:62872ee396a8 56 /**
yamaguch 6:d9489d50669d 57 * reads the revision number
yamaguch 5:62872ee396a8 58 *
yamaguch 5:62872ee396a8 59 * @returns revision number
yamaguch 5:62872ee396a8 60 */
yamaguch 5:62872ee396a8 61 int revision();
yamaguch 5:62872ee396a8 62
yamaguch 5:62872ee396a8 63 /**
yamaguch 5:62872ee396a8 64 * checks if data is ready
yamaguch 5:62872ee396a8 65 *
yamaguch 5:62872ee396a8 66 * @returns true if data is ready, false otherwise
yamaguch 5:62872ee396a8 67 */
yamaguch 5:62872ee396a8 68 bool isReady();
yamaguch 5:62872ee396a8 69
yamaguch 5:62872ee396a8 70 /**
yamaguch 5:62872ee396a8 71 * performs software reset
yamaguch 5:62872ee396a8 72 */
yamaguch 5:62872ee396a8 73 void reset();
yamaguch 5:62872ee396a8 74
yamaguch 5:62872ee396a8 75 /**
yamaguch 5:62872ee396a8 76 * sets the operation mode
yamaguch 5:62872ee396a8 77 */
yamaguch 5:62872ee396a8 78 void setOperationMode(OperationMode mode);
yamaguch 5:62872ee396a8 79
yamaguch 5:62872ee396a8 80 /**
yamaguch 5:62872ee396a8 81 * performs self test
yamaguch 5:62872ee396a8 82 *
yamaguch 5:62872ee396a8 83 * @returns the result of the test (true if succeeded, false otherwise)
yamaguch 5:62872ee396a8 84 */
yamaguch 5:62872ee396a8 85 bool performSelfTest();
yamaguch 5:62872ee396a8 86
yamaguch 5:62872ee396a8 87 /**
yamaguch 5:62872ee396a8 88 * reads the current pressure
yamaguch 5:62872ee396a8 89 *
yamaguch 6:d9489d50669d 90 * @param waitForDataReady if true, it will wait until data becomes ready
yamaguch 5:62872ee396a8 91 *
yamaguch 5:62872ee396a8 92 * @returns pressure in hectopascal (hPa)
yamaguch 5:62872ee396a8 93 */
yamaguch 7:41606315d260 94 float readPressure(bool waitForDataReady = true);
yamaguch 5:62872ee396a8 95
yamaguch 5:62872ee396a8 96 /**
yamaguch 5:62872ee396a8 97 * reads the current temperature
yamaguch 5:62872ee396a8 98 *
yamaguch 6:d9489d50669d 99 * @param waitForDataReady if true, it will wait until data becomes ready
yamaguch 5:62872ee396a8 100 *
yamaguch 5:62872ee396a8 101 * @returns temperature in Celsius
yamaguch 5:62872ee396a8 102 */
yamaguch 7:41606315d260 103 float readTemperature(bool waitForDataReady = true);
yamaguch 5:62872ee396a8 104
yamaguch 5:62872ee396a8 105 private:
yamaguch 5:62872ee396a8 106 enum RegisterName {
yamaguch 5:62872ee396a8 107 REVID = 0x00, // ASIC revision number
yamaguch 5:62872ee396a8 108 OPERATION = 0x03, // Operation register
yamaguch 5:62872ee396a8 109 OPSTATUS = 0x04, // Operation status
yamaguch 5:62872ee396a8 110 RSTR = 0x06, // ASIC software reset
yamaguch 5:62872ee396a8 111 STATUS = 0x07, // ASIC top-level status
yamaguch 5:62872ee396a8 112 DATARD8 = 0x1F, // Pressure output data (MSB)
yamaguch 5:62872ee396a8 113 DATARD16 = 0x20, // Pressure output data (LSB, 16 bits)
yamaguch 5:62872ee396a8 114 TEMPOUT = 0x21, // Temperature output data (16 bits)
yamaguch 5:62872ee396a8 115 };
yamaguch 5:62872ee396a8 116
yamaguch 5:62872ee396a8 117 enum Command {
yamaguch 5:62872ee396a8 118 READ = 0x00, // SCP1000 READ command
yamaguch 5:62872ee396a8 119 WRITE = 0x02, // SCP1000 WRITE command
yamaguch 5:62872ee396a8 120 };
yamaguch 5:62872ee396a8 121
yamaguch 5:62872ee396a8 122 SPI spi;
yamaguch 5:62872ee396a8 123 DigitalOut selectPin;
yamaguch 5:62872ee396a8 124
yamaguch 5:62872ee396a8 125 int readRegister(RegisterName registerName, bool twoBytes = 0);
yamaguch 5:62872ee396a8 126 void writeRegister(RegisterName registerName, char value);
yamaguch 5:62872ee396a8 127 };
yamaguch 5:62872ee396a8 128
yamaguch 5:62872ee396a8 129 #endif