SCP1000 Library
Dependents: SCP1000Example 0sample_SCP1000_USB SCP1000_Fastsensing
Diff: SCP1000.h
- Revision:
- 5:62872ee396a8
- Child:
- 6:d9489d50669d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SCP1000.h Tue Feb 08 07:31:09 2011 +0000 @@ -0,0 +1,107 @@ +#ifndef SCP1000_H +#define SCP1000_H + +#include "mbed.h" + +/** + * SCP1000 pressure/temperature sensor + */ + +class SCP1000 { +public: + enum OperationMode { + CANCEL = 0x00, + HIGH_SPEED_MODE = 0x09, + HIGH_RESOLUTION_MODE = 0x0A, + ULTRA_LOW_POWER_MODE = 0x0B, + LOW_POWER = 0x0C, + SELF_TEST = 0x0F, + }; + + /** + * creates an SCP1000 interface with specified pins + * + * @param PinName mosi SPI MOSI pin + * @param PinName miso SPI MISO pin + * @param PinName sclk SPI SCLK pin + * @param PinName cs SPI CS pin + * @param OperationMode mode Initial operation mode + */ + SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs, OperationMode mode = HIGH_RESOLUTION_MODE); + + ~SCP1000() {}; + + /** + * reads revision number + * + * @returns revision number + */ + int revision(); + + /** + * checks if data is ready + * + * @returns true if data is ready, false otherwise + */ + bool isReady(); + + /** + * performs software reset + */ + void reset(); + + /** + * sets the operation mode + */ + void setOperationMode(OperationMode mode); + + /** + * performs self test + * + * @returns the result of the test (true if succeeded, false otherwise) + */ + bool performSelfTest(); + + /** + * reads the current pressure + * + * @param waitForDataReady if true, it will wait until data becomes ready to read + * + * @returns pressure in hectopascal (hPa) + */ + float readPressure(bool waitForDataReady = false); + + /** + * reads the current temperature + * + * @param waitForDataReady if true, it will wait until data becomes ready to read + * + * @returns temperature in Celsius + */ + float readTemperature(bool waitForDataReady = false); + +private: + enum RegisterName { + REVID = 0x00, // ASIC revision number + OPERATION = 0x03, // Operation register + OPSTATUS = 0x04, // Operation status + RSTR = 0x06, // ASIC software reset + STATUS = 0x07, // ASIC top-level status + DATARD8 = 0x1F, // Pressure output data (MSB) + DATARD16 = 0x20, // Pressure output data (LSB, 16 bits) + TEMPOUT = 0x21, // Temperature output data (16 bits) + }; + + enum Command { + READ = 0x00, // SCP1000 READ command + WRITE = 0x02, // SCP1000 WRITE command + }; + + SPI spi; + DigitalOut selectPin; + + int readRegister(RegisterName registerName, bool twoBytes = 0); + void writeRegister(RegisterName registerName, char value); +}; + +#endif \ No newline at end of file