The following is the code for the
#include <SPI.h>
#include <SD.h>
/*
CONNECTIONS:
BAROMETRIC PRESSURE
D10 SCP1000: CSB (CHIP SELECT BAR)
D11 SCP1000: MOSI (DATA OUT)
D12 SCP1000: MISO (DATA IN)
D13 SCP1000: SCK (SPEED CLOCK)
GND GND
3.3V VCC+ (IMPORTANT: USES ONLY +3.3V)
*/
//USES THE SCP1000 PRESSURE/TEMPERATURE SENSOR
// define spi bus pins
#define SLAVESELECT 10
#define SPICLOCK 13
#define DATAOUT 11 //MOSI
#define DATAIN 12 //MISO
#define UBLB(a,b) ( ( (a) << 8) | (b) )
#define UBLB19(a,b) ( ( (a) << 16 ) | (b) )
//Addresses
#define REVID 0x00 //ASIC Revision Number
#define OPSTATUS 0x04 //Operation Status
#define STATUS 0x07 //ASIC Status
#define START 0x0A //Constant Readings
#define PRESSURE 0x1F //Pressure 3 MSB
#define PRESSURE_LSB 0x20 //Pressure 16 LSB
#define TEMP 0x21 //16 bit temp
//SD shield
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 3;
void setup() {
// initialize Serial Port interface
Serial.begin(9600);
// INITIALIZATION OF THE SCP1000 PRESSURE PINS
byte clr;
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
SPCR = B01010011; //MPIE=0, SPE=1 (on), DORD=0 (MSB first), MSTR=1 (master), CPOL=0 (clock idle when low), CPHA=0 (samples MOSI on rising edge), SPR1=0 & SPR0=0 (500kHz)
clr=SPSR;
clr=SPDR;
//Initializes the SD card (code by Tom Igoe, from Public Domain)
Serial.print("Initializing SD card...\n");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// INITIALIZATION OF THE SD CARD
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
delay(10);
//Serial.println("Initialize High Speed Constant Reading Mode");
write_register(0x03,0x09);
}