Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf mbed TMP102 HTTPServer ADJD-S371_ColourSens
Revision 2:1cc34c25b99d, committed 2011-02-04
- Comitter:
- MichaelW
- Date:
- Fri Feb 04 11:10:22 2011 +0000
- Parent:
- 1:0f7aff70292e
- Commit message:
- Updated RPCInterface Library
Changed in this revision
--- a/RPCInterface.lib Fri Oct 01 14:29:46 2010 +0000 +++ b/RPCInterface.lib Fri Feb 04 11:10:22 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/MichaelW/code/RPCInterface/#05f0d66bee57 +http://mbed.org/users/MichaelW/code/RPCInterface/#a9e2c45097c8
--- a/scp1000-D01.lib Fri Oct 01 14:29:46 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/MichaelW/code/scp1000-D01/#d509ab38e2b5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scp1000-D01/scp1000.cpp Fri Feb 04 11:10:22 2011 +0000
@@ -0,0 +1,153 @@
+/**
+* @section LICENSE
+*Copyright (c) 2010 ARM Ltd.
+*
+*Permission is hereby granted, free of charge, to any person obtaining a copy
+*of this software and associated documentation files (the "Software"), to deal
+*in the Software without restriction, including without limitation the rights
+*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+*copies of the Software, and to permit persons to whom the Software is
+*furnished to do so, subject to the following conditions:
+*
+*The above copyright notice and this permission notice shall be included in
+*all copies or substantial portions of the Software.
+*
+*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+*THE SOFTWARE.
+*
+*
+* @section DESCRIPTION
+* Library for using the SCP1000-D01 MEMS Pressure sensor, this is the SPI version. This library only supports high resolution mode.
+* Communication with the sensor is via a 4 wire interface
+*
+*/
+
+#include "scp1000.h"
+
+SCP1000::SCP1000(PinName mosi, PinName miso, PinName sck, PinName CSB):
+ _spi(mosi, miso, sck),
+ _CSB(CSB)
+ {
+ _CSB = 1;
+ wait(0.1);
+ _CSB = 0;
+ //Force reset
+ _spi.write(((0x06<< 2) | 0x02));
+ _spi.write(0x01);
+ _CSB = 1;
+ wait(0.06);
+ _CSB = 0;
+ //Check starup Procedure has finished
+ int status;
+ do{
+ _spi.write(0x07 << 2);
+ status = _spi.write(0x00);
+ //printf("waiting for startup to finish %i\n", status);
+ wait(0.1);
+ }while((status & 0x01)); //Wait for LSB to go low
+ //Test for error in intialisation
+ _spi.write(0x1F << 2);
+ status = _spi.write(0x00);
+ if(!(status & 0x01)){
+ //printf("Error in Intialisation");
+ return;
+ }
+
+
+ //Set mode as 0x00
+ _spi.write((0x03 << 2) | 0x02);
+ _spi.write(0x00);
+ wait(0.05);
+
+ //Check DRDDY is low, if not read data
+ _spi.write(0x07 << 2);
+ status = _spi.write(0x00);
+ if(status & 0x20){
+ //printf("Data to be read");
+ _spi.write(0x1F <<2);
+ _spi.write(0x00); //read and discard data
+ _spi.write(0x20 <<2);
+ _spi.write(0x00); //read and discard data
+ _spi.write(0x00); //read and discard data
+ }
+
+ //Check OPStatus bit
+ _spi.write(0x04 << 2);
+ status = _spi.write(0x0);
+ if(status & 0x01){
+ //printf("Not finished");
+ }
+
+ //Activate new mode
+ _spi.write((0x03 << 2) | 0x02);
+ _spi.write(0x0A);
+}
+float SCP1000::read(){
+ _CSB = 0;
+
+ if(_waitReady() == 1){
+ _spi.write(0x1F <<2);
+ int PressureHighest = _spi.write(0x00);
+ _spi.write(0x20 <<2);
+ int PressureHigh = _spi.write(0x00);
+ int Pressurelow = _spi.write(0x00);
+
+ int pressureValue = Pressurelow | PressureHigh << 8 | (PressureHighest & 0x07) << 16;
+ float pressure = ((float)pressureValue) / 4;
+
+ _CSB = 1;
+
+ return(pressure);
+ }else{
+ return(0);
+ }
+}
+float SCP1000::readTemperature(){
+
+ _CSB = 0;
+
+ if(_waitReady() == 1){
+ //ready so now read
+ _spi.write(0x21 << 2);
+ int TempHigh = _spi.write(0x00);
+ int TempLow = _spi.write(0x00);
+
+ signed int temperatureValue = (TempLow | ((TempHigh & 0x1F) << 8));
+ if(TempHigh & 0x20){
+ //negative
+ temperatureValue = -8192 + temperatureValue;
+ }else{
+ //positive
+ }
+
+ float temperature = ((float)temperatureValue) * 0.05;
+ _CSB = 1;
+ return(temperature);
+ }else{
+ return(0);
+ }
+}
+
+ int SCP1000::_waitReady(){
+ //Depending on mode wait for it to be ready - only supports high resolution mode - wait for bit 5 to be set in 00
+ int status;
+ _CSB = 0;
+ do{
+ _spi.write(0x07 << 2);
+ status = _spi.write(0x00);
+ //printf("waiting %i\n", status);
+ wait(0.2);
+ if(status & 0x10){
+ //bit 4 high - real time error, interrupt has not been read in time - read DataRD16
+ _spi.write(0x20 << 2);
+ int data = _spi.write(0x00);
+ data = _spi.write(0x00);
+ }
+ }while(!(status & 0x20));
+ return(1);
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scp1000-D01/scp1000.h Fri Feb 04 11:10:22 2011 +0000
@@ -0,0 +1,84 @@
+/**
+* @section LICENSE
+*Copyright (c) 2010 ARM Ltd.
+*
+*Permission is hereby granted, free of charge, to any person obtaining a copy
+*of this software and associated documentation files (the "Software"), to deal
+*in the Software without restriction, including without limitation the rights
+*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+*copies of the Software, and to permit persons to whom the Software is
+*furnished to do so, subject to the following conditions:
+*
+*The above copyright notice and this permission notice shall be included in
+*all copies or substantial portions of the Software.
+*
+*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+*THE SOFTWARE.
+*
+*
+* @section DESCRIPTION
+* Library for using the SCP1000-D01 MEMS Pressure sensor
+*
+*/
+
+#ifndef SCP1000_D01_H_
+#define SCP1000_D01_H_
+/**
+* Includes
+*/
+#include "mbed.h"
+/**
+* Class to allow reading of the SCP1000-D01 mems pressure sensor (SPI mode). The class currently only supports High resolution mode.
+* This means that the sensor can be read at a maximum rate of 1.8Hz.
+*/
+class SCP1000{
+public:
+ /**
+ *Constructor
+ *
+ * @param mosi The MOSI pin for the SPI interface
+ * @param miso The MISO pin for the SPI interface
+ * @param CSB The Chip select on the SCP1000
+ */
+ SCP1000(PinName mosi, PinName miso, PinName sck, PinName CSB);
+
+ /**
+ * Read the current Pressure.
+ * This blocks until the sensor has completed a reading
+ *
+ * @returns The pressure in pascals (N/m2)
+ */
+ float read();
+ /**
+ * Reads the temperature as measured by the SCP1000.
+ * This blocks until the sensor has completed a reading
+ *
+ *@returns The temperature in degrees celsius
+ */
+ float readTemperature();
+
+
+
+private:
+ /**
+ * Method which blocks until the sensor is ready to be read.
+ * @returns 1 when successful.
+ */
+ int _waitReady();
+ //Interfaces
+ SPI _spi;
+ DigitalOut _CSB;
+
+ //Pins that woudl be required to use SCP1000 in different modes
+ // DigitalIn _DRDY; //Interrupt data ready - also need to be able to attach a function to this class
+ // DigitalOut _TRIG; //Trigger
+ // DigitalOut _PD; //Power Down
+
+
+};
+#endif
\ No newline at end of file