SCP1000-D01 MEMS pressure sensor library
Diff: scp1000.cpp
- Revision:
- 4:d509ab38e2b5
- Parent:
- 3:29c98bdee20b
--- 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{