SCP1000 Library
Dependents: SCP1000Example 0sample_SCP1000_USB SCP1000_Fastsensing
SCP1000.h
- Committer:
- yamaguch
- Date:
- 2011-02-04
- Revision:
- 2:4c2784b363ad
- Parent:
- 0:23fab9b42ad4
- Child:
- 3:8edd2b18c755
File content as of revision 2:4c2784b363ad:
#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, }; /** * Constructor * * @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, otherwise false */ bool isReady(); /** * Perform software reset */ void reset(); /** * Set operation mode */ void setOperationMode(OperationMode mode); /** * Perform self test * * @returns Result of the test (true if succeeded, otherwise false) */ bool performSelfTest(); /** * Read pressure * * @param waitForDataReady if true, waits until data becomes ready to read * * @returns Pressure in hectopascal */ float readPressure(bool waitForDataReady = false); /** * Read temperature * * @param waitForDataReady if true, waits 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