Hi, I am trying to program for a pressure sensor which uses the SPI protocol. However, it seems like that my code doesn't run properly. Can some one help me with this? I just want to measure the fluid pressure--Pdc. I appreciate that a lot!!!
Here is the datasheet
#include <SPI.h> // include the SPI library
const int cs = 10;
const byte sample = 10000011;
const byte resend = 01010000;
void setup(){
pinMode(cs,OUTPUT);
Serial.begin(9600);//initialize the serial monitor
Serial.println("Initializing the force monitor");
delay(50);//give the numatac some time to setup
SPI.begin();//begin SPI trasaction
digitalWrite(cs,HIGH);
}
void loop(){
//Set up SPI bus
//set the clock speed to be 5 Mhz, most significant byte first, and data trasfer mode 0
SPI.beginTransaction(SPISettings(4400000,MSBFIRST,SPI_MODE0));
uint8_t MSBbyte, LSBbyte;
digitalWrite(cs,LOW);
SPI.transfer(sample);
SPI.transfer(sample);
digitalWrite(cs,HIGH);
delayMicroseconds(50);
digitalWrite(cs,LOW);
MSBbyte = SPI.transfer(resend);
LSBbyte = SPI.transfer(resend);
SPI.endTransaction();
digitalWrite(cs,HIGH);
MSBbyte = unsigned(MSBbyte)>> 1;
LSBbyte = unsigned(LSBbyte)>> 3;
LSBbyte <<= 3;
unsigned int rawdata = MSBbyte*256 + LSBbyte;
unsigned int pressure = unsigned(rawdata) >> 3;
Serial.println(pressure);