SCP1000-D01 MEMS pressure sensor library

Files at this revision

API Documentation at this revision

Comitter:
MichaelW
Date:
Tue Sep 28 08:28:48 2010 +0000
Parent:
3:29c98bdee20b
Commit message:
Code improvements

Changed in this revision

scp1000.cpp Show annotated file Show diff for this revision Revisions of this file
scp1000.h Show annotated file Show diff for this revision Revisions of this file
diff -r 29c98bdee20b -r d509ab38e2b5 scp1000.cpp
--- a/scp1000.cpp	Mon Sep 27 11:43:27 2010 +0000
+++ b/scp1000.cpp	Tue Sep 28 08:28:48 2010 +0000
@@ -50,11 +50,12 @@
         //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");
+        //printf("Error in Intialisation");
+        return;
     }
     
     
@@ -67,26 +68,25 @@
     _spi.write(0x07 << 2);
     status = _spi.write(0x00);
     if(status & 0x20){
-        printf("Data to be read");
+       //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");
+        //printf("Not finished");
     }   
     
     //Activate new mode
     _spi.write((0x03 << 2) | 0x02);
     _spi.write(0x0A);
-    
-    
-    
 }
-
-
-    
 float SCP1000::read(){
     _CSB = 0;
 
@@ -97,14 +97,11 @@
         int PressureHigh = _spi.write(0x00);
         int Pressurelow = _spi.write(0x00);
         
-        
-        int pressureValue = Pressurelow | PressureHigh << 8 | (PressureHighest & 0x07) << 16;
-        
+        int pressureValue = Pressurelow | PressureHigh << 8 | (PressureHighest & 0x07) << 16;       
         float pressure = ((float)pressureValue) / 4;
-        
+ 
         _CSB = 1;
-    
-    
+
         return(pressure);
     }else{
         return(0);
@@ -125,10 +122,9 @@
             //negative
             temperatureValue = -8192 + temperatureValue;
         }else{
-            //positive
-            
+            //positive         
         }
-        
+
         float temperature = ((float)temperatureValue) * 0.05;
         _CSB = 1;
         return(temperature);
@@ -138,7 +134,7 @@
 }
     
  int SCP1000::_waitReady(){
-    //Depending on mode wait for it to be ready
+    //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{
diff -r 29c98bdee20b -r d509ab38e2b5 scp1000.h
--- a/scp1000.h	Mon Sep 27 11:43:27 2010 +0000
+++ b/scp1000.h	Tue Sep 28 08:28:48 2010 +0000
@@ -26,10 +26,11 @@
 *
 */
 
-
 #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.
@@ -47,17 +48,17 @@
     SCP1000(PinName mosi, PinName miso, PinName sck, PinName CSB);
 
     /**
-    *Read the current Pressure.
-    *This blocks until the sensor has completed a reading
+    * Read the current Pressure.
+    * This blocks until the sensor has completed a reading
     * 
-    * @returns The pressure in pascals
+    * @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
+    *@returns The temperature in degrees celsius
     */
     float readTemperature();
     
@@ -66,7 +67,7 @@
 private:
     /**
     * Method which blocks until the sensor is ready to be read.
-    * Returns 1 when successful.
+    * @returns 1 when successful.
     */
     int _waitReady();
     //Interfaces