SPI timings

Hi,
I'm trying to read data from a Honeywell RSC pressure sensor. I've got the bare bones done below (there are calibrations etc. that need to be read and integrated still) but I'm finding it necessary to put delays in between SPI.transfers to get any values, and it then seems to matter a lot what exactly those delays are. It also doesn't get any values the first time it runs the loop after the setup section. There doesn't seem to be any timings for the SPI communication in the datasheet though.

Can anyone give me a bit of help please?

Many thanks

This is the pressure reading part:

void loop() {
  ///////////////////////////////////////////////////////////////////////////////////////////////
  //Read Pressure
  digitalWrite(CSADC, LOW);
  //delay(100);
  SPI.transfer(68); //write to register 1
  delay(10);
  SPI.transfer(4);  //pressure mode

  delay(10);

  SPI.transfer(0x08);  //start conversion
  //delay(10);
  int p1 = SPI.transfer(0);

  //delay(10);
  int p2 = SPI.transfer(0);

  //delay(100);
  int p3 = SPI.transfer(0);

  digitalWrite(CSADC, HIGH);

  long p4 = p1 * 65536 + p2 * 256 + p3;

  float RSCpress = 20*(-1.0+p4/8388608.0);

  Serial.print("p1 = "); Serial.println(p1);
  Serial.print("p2 = "); Serial.println(p2);
  Serial.print("p3 = "); Serial.println(p3);
  Serial.print("p4 = "); Serial.println(p4);
  Serial.print("RSCpress = "); Serial.println(RSCpress, 10);
  Serial.println("");

  //digitalWrite(CSADC, HIGH);
///////////////////////////////////////////////////////////////////////////////////////////////
  delay(1000);
  //4. Command the ADC to take a temperature reading, and store this reading.
  //5. Give Delay (Example: if sample rate is 330SPS delay for 3.03 ms [1/330 s]).
  //6. Command the ADC to take a pressure reading, and store this reading.
  //7. Apply the compensation formulae to the temperature and pressure readings in order to calculate a pressure value.
  //8. Repeat steps 4, 5 and 6 in a loop to take additional readings.
}

This is the full code (what I've done of it so far - there should be enough so far to get pressure readings, just not compensated ones though):

#include <SPI.h>

int DRDY      =  4;
int CSEE      =  6;
int CSADC     =  8;

void setup() {
  pinMode (CSEE, OUTPUT);
  digitalWrite(CSEE, HIGH);
  pinMode (CSADC, OUTPUT);
  digitalWrite(CSADC, HIGH);
  pinMode (DRDY, INPUT_PULLUP);
  //digitalWrite(DRDY, HIGH);

  //set data rate for serial monitor
  Serial.begin(115200);

  // initialize SPI:
  //CS_EE and CS_ADC must never be simultaneously low.
  //EEPROM operates in SPI mode 0 where CPOL = 0 and CPHA = 0 (0,0) and mode 3 where CPOL = 1 and CPHA = 1 (1,1).
  SPI.begin();
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));

  ///////////////////////////////////////////////////////////////////////////////////////////////
  //1. Read the ADC settings and the compensation values from EEPROM.
  digitalWrite(CSEE, LOW);

  //prange
  SPI.transfer16(795);
  float prange;
  union u_tag {
    byte b[4];
    float fval;
  } u;
  u.b[0] = SPI.transfer(0);
  u.b[1] = SPI.transfer(0);
  u.b[2] = SPI.transfer(0);
  u.b[3] = SPI.transfer(0);
  prange = u.fval;
  Serial.print("prange = "); Serial.println(prange, 10);

  //pminimum
  float pminimum;
  union v_tag {
    byte b[4];
    float fval;
  } v;
  v.b[0] = SPI.transfer(0);
  v.b[1] = SPI.transfer(0);
  v.b[2] = SPI.transfer(0);
  v.b[3] = SPI.transfer(0);
  pminimum = v.fval;
  Serial.print("pminimum = "); Serial.println(pminimum, 10);

  //punits
  byte pu1 = SPI.transfer(0);
  byte pu2 = SPI.transfer(0);
  byte pu3 = SPI.transfer(0);
  byte pu4 = SPI.transfer(0);
  byte pu5 = SPI.transfer(0);
  char punits[] = {pu1, pu2, pu3, pu4, pu5};
  Serial.print("punits = "); Serial.println(punits);

  //pref
  char pref = SPI.transfer(0);

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  //ADC config
  SPI.transfer16(829);
  unsigned int  ADCconfig1 = SPI.transfer(0); //start reading byte 61 (ADC config settings)
  SPI.transfer(0);
  unsigned int  ADCconfig2 = SPI.transfer(0);
  SPI.transfer(0);
  unsigned int  ADCconfig3 = SPI.transfer(0);
  SPI.transfer(0);
  unsigned int  ADCconfig4 = SPI.transfer(0);

  digitalWrite(CSEE, HIGH);

  //POLYNOMIAL COEFFICIENTS - 130 to 145
  SPI.transfer16(898); //start reading byte 130 (Polynomial Coefficients)

  //Span coefficients 210 to 225

  //Shape coefficients 290 to 305

  ///////////////////////////////////////////////////////////////////////////////////////////////
  //2. Initialize the ADC converter using the settings provided in EEPROM.
  //The ADC interface operates in SPI mode 1 where CPOL = 0 and CPHA = 1.
  //To program a configuration register, the host sends a WREG command [0100 RRNN], where ‘RR’ is the register number and ‘NN’ is the number of bytes to be written –1.
  //config reg 1 should be 4 for pressure sensing, or 6 for temperature sensing
  SPI.endTransaction();
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE1));
  SPI.begin();

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSADC, LOW);
  SPI.transfer(6); //reset ADC
  SPI.transfer(67); //write 4 bytes starting at reg 0
  SPI.transfer(ADCconfig1);
  SPI.transfer(ADCconfig2);
  SPI.transfer(ADCconfig3);
  SPI.transfer(ADCconfig4);
  
  digitalWrite(CSADC, HIGH);

///////////////////////////////////////////////////////////////////////////////////////////////
  //Read Temperature
  digitalWrite(CSADC, LOW);
  //delay(100);
  SPI.transfer(68); //write to register 1
  delay(100);
  SPI.transfer(6);  //temperature mode

  delay(100);

  SPI.transfer(0x08);  //start conversion
  //delay(100);
  int t1 = SPI.transfer(0);

  //delay(100);
  int t2 = SPI.transfer(0);

  delay(100);
  int t3 = SPI.transfer(0);

  digitalWrite(CSADC, HIGH);

  int t4 = t1 * 256 + t2;
  int t5 = t4 >> 2;

  float RSCtemp = t5 * 0.03125;

  Serial.print("t1 = "); Serial.println(t1);
  Serial.print("t2 = "); Serial.println(t2);
  Serial.print("t4 = "); Serial.println(t4);
  Serial.print("t5 = "); Serial.println(t5);
  Serial.print("RSCtemp = "); Serial.println(RSCtemp);

  //digitalWrite(CSADC, HIGH);
///////////////////////////////////////////////////////////////////////////////////////////////
  
delay (200);
  //3. Adjust the ADC sample rate if desired.
}

void loop() {
  ///////////////////////////////////////////////////////////////////////////////////////////////
  //Read Pressure
  digitalWrite(CSADC, LOW);
  //delay(100);
  SPI.transfer(68); //write to register 1
  delay(10);
  SPI.transfer(4);  //pressure mode

  delay(10);

  SPI.transfer(0x08);  //start conversion
  //delay(10);
  int p1 = SPI.transfer(0);

  //delay(10);
  int p2 = SPI.transfer(0);

  //delay(100);
  int p3 = SPI.transfer(0);

  digitalWrite(CSADC, HIGH);

  long p4 = p1 * 65536 + p2 * 256 + p3;

  float RSCpress = 20*(-1.0+p4/8388608.0);

  Serial.print("p1 = "); Serial.println(p1);
  Serial.print("p2 = "); Serial.println(p2);
  Serial.print("p3 = "); Serial.println(p3);
  Serial.print("p4 = "); Serial.println(p4);
  Serial.print("RSCpress = "); Serial.println(RSCpress, 10);
  Serial.println("");

  //digitalWrite(CSADC, HIGH);
///////////////////////////////////////////////////////////////////////////////////////////////
  delay(1000);
  //4. Command the ADC to take a temperature reading, and store this reading.
  //5. Give Delay (Example: if sample rate is 330SPS delay for 3.03 ms [1/330 s]).
  //6. Command the ADC to take a pressure reading, and store this reading.
  //7. Apply the compensation formulae to the temperature and pressure readings in order to calculate a pressure value.
  //8. Repeat steps 4, 5 and 6 in a loop to take additional readings.
}

Hi everyone again,

I've got it working now (I think!) but still seem to need the delays and have no idea why and would love it if anyone could suggest to me why it might be please?

There is in fact a timings diagram in the datasheet but it isn't enlightening on the above at all. I also can't get it to command the sensor to take a temperature reading, so there must be issues with my code which I don't undertand myself.

I've put together with an HSC sensor, (and it uses this temperature reading instead to calibrate itself) and the code for the two is below if its useful to anyone:

Cheers

#include <SPI.h>
#include <math.h>

///////////////////////////////////////////////////////////////////////////////////////////////
//PINS//
int CSHSCADC     =  2;
int DRDY      =  3;
int CSEE      =  6;
int CSRSCADC     =  8;

///////////////////////////////////////////////////////////////////////////////////////////////
//OFFSETS//
float RSCoffset = 0.0;
float HSCoffset = 0.025;
///////////////////////////////////////////////////////////////////////////////////////////////

float noaverages = 10.0;

float RSCaverage = 0.0;
float HSCaverage = 0.0;

int i = 0;
int j = 0;

int HSCstatus = 0;
float HSCtemp2 = 0.0;
float HSCpressure = 0.0;

int result2 = 0;

float RSCpcomp = 0.0;

unsigned char  ADCconfig1 = 0;
unsigned char  ADCconfig2 = 0;
unsigned char  ADCconfig3 = 0;
unsigned char  ADCconfig4 = 0;

float poly0 = 0.0;
float poly1 = 0.0;
float poly2 = 0.0;
float poly3 = 0.0;

float shape0 = 0.0;
float shape1 = 0.0;
float shape2 = 0.0;
float shape3 = 0.0;

float span0 = 0.0;
float span1 = 0.0;
float span2 = 0.0;
float span3 = 0.0;

float prange = 0.0;
float pminimum = 0.0;
char punits[5];

void setup() {
  pinMode (CSHSCADC, OUTPUT);
  digitalWrite(CSHSCADC, HIGH);

  pinMode (CSEE, OUTPUT);
  digitalWrite(CSEE, HIGH);
  pinMode (CSRSCADC, OUTPUT);
  digitalWrite(CSRSCADC, HIGH);
  pinMode (DRDY, INPUT_PULLUP);
  //digitalWrite(DRDY, HIGH);

  //set data rate for serial monitor
  Serial.begin(115200);

  // initialize SPI:
  //CS_EE and CS_ADC must never be simultaneously low.
  //EEPROM operates in SPI mode 0 where CPOL = 0 and CPHA = 0 (0,0) and mode 3 where CPOL = 1 and CPHA = 1 (1,1).
  SPI.begin();
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));

  ///////////////////////////////////////////////////////////////////////////////////////////////
  //1. Read the ADC settings and the compensation values from EEPROM.
  digitalWrite(CSEE, LOW);

  //prange
  SPI.transfer16(795); //read from address 27
  prange = readfloat();
  pminimum = readfloat();

  //punits
  byte pu1 = SPI.transfer(0);
  byte pu2 = SPI.transfer(0);
  byte pu3 = SPI.transfer(0);
  byte pu4 = SPI.transfer(0);
  byte pu5 = SPI.transfer(0);
  char punits [] = {pu1, pu2, pu3, pu4, pu5};

  //pref
  char pref = SPI.transfer(0);

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  //ADC config
  SPI.transfer16(829);
  ADCconfig1 = SPI.transfer(0); //start reading byte 61 (ADC config settings)
  SPI.transfer(0);
  ADCconfig2 = SPI.transfer(0);
  SPI.transfer(0);
  ADCconfig3 = SPI.transfer(0);
  SPI.transfer(0);
  ADCconfig4 = SPI.transfer(0);

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  //POLYNOMIAL COEFFICIENTS - 130 to 145
  SPI.transfer16(898); //start reading byte 130 (Polynomial Coefficients)
  poly0 = readfloat();
  poly1 = readfloat();
  poly2 = readfloat();
  poly3 = readfloat();

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  //Span coefficients 210 to 225
  SPI.transfer16(978); //start reading byte 210
  span0 = readfloat();
  span1 = readfloat();
  span2 = readfloat();
  span3 = readfloat();

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  //Shape coefficients 290 to 305
  SPI.transfer16(2850); //start reading byte 290
  shape0 = readfloat();
  shape1 = readfloat();
  shape2 = readfloat();
  shape3 = readfloat();

  //Checksum 450
  //SPI.transfer16(3010); //start reading byte 290
  digitalWrite(CSEE, HIGH);

  //2. Initialize the ADC converter using the settings provided in EEPROM.
  SPI.endTransaction();
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE1));
  SPI.begin();

  digitalWrite(CSRSCADC, LOW);
  SPI.transfer(6); //reset ADC
  SPI.transfer(67); //write 4 bytes starting at reg 0
  SPI.transfer(ADCconfig1);
  SPI.transfer(ADCconfig2);
  SPI.transfer(ADCconfig3);
  SPI.transfer(ADCconfig4);

  digitalWrite(CSRSCADC, HIGH);
}
void loop() {
  j = 0;
  
  for (j = 0; j < noaverages; j++) {
    ///////////////////////////////////////////////////////////////////////////////////////////////
    //HSC PRESSURE//////////////////
    digitalWrite(CSHSCADC, LOW);
    int data1 = SPI.transfer(0);
    int data2 = SPI.transfer(0);
    int data3 = SPI.transfer(0);
    int data4 = SPI.transfer(0);
    digitalWrite(CSHSCADC, HIGH);
    HSCstatus = data1 >> 6;
    result2 = (data1 << 8);
    result2 = result2 | data2;
    result2 = result2 - HSCstatus;
    int HSCtemp = (data3 << 3) | (data4 >> 5);
    HSCtemp2 = 200.0 * (HSCtemp / 2047.0) - 50;
    int HSCresult = result2;
    int pressureMin = -60;
    int pressureMax = 60;
    int outputMax = 14745; // 90% 0f 2^14 counts
    int outputMin = 1638; // 10%
    int output = HSCresult;

    //Serial.print("data1 = "); Serial.println(data1);
    //Serial.print("data2 = "); Serial.println(data2);
    //Serial.print("data3 = "); Serial.println(data3);
    //Serial.print("data4 = "); Serial.println(data4);
    //Serial.print("result2 = "); Serial.println(result2);
    //Serial.print("HSCstatus = "); Serial.println(HSCstatus);
    //Serial.print("HSCresult = "); Serial.println(HSCresult);

    float output1 = (HSCresult - outputMin);
    //Serial.print("output1="); Serial.println(output1);
    int pressure1 = (pressureMax - pressureMin);
    //Serial.print("pressure1="); Serial.println(pressure1);
    int output2 = (outputMax - outputMin);
    //Serial.print("output2="); Serial.println(output2);
    float pressurePsi = output1 * pressure1;
    //Serial.print("pressurePSI="); Serial.print(pressurePsi);
    HSCpressure = (pressurePsi / output2) + pressureMin;
    HSCpressure -= HSCoffset;

    ///////////////////////////////////////////////////////////////////////////////////////////////
    //RSC PRESSURE//////////////////

    digitalWrite(CSRSCADC, LOW);

    delay(50);

    SPI.transfer(68); //write to register 1
    delay(50);
    SPI.transfer(4);  //pressure mode
    delay(100); //needs to be >10??
    SPI.transfer(8);  //start conversion
    delay(100);

    union sfp24bit {
      byte b[4];
      long result;
    } tval;

    int32_t p1 = SPI.transfer(0);
    int32_t p2 = SPI.transfer(0);
    int32_t p3 = SPI.transfer(0);
    //int32_t pintcheck = SPI.transfer(0);

    digitalWrite(CSRSCADC, HIGH);

    // convert three bytes signed 24 bit integer to signed long
    tval.b[0] = p3; // low byte
    tval.b[1] = p2; // middle byte
    tval.b[2] = p1; // high byte
    if (p1 > 127) {
      tval.b[3] = 255;
    }
    else {
      tval.b[3] = 0;
    }

    long p4 = tval.result;

    float p5 = 20 * (p4 / 8388608.0);

    float RSCtemp = HSCtemp2 / 0.03125;

    float pintcalc = polyeq(poly3, poly2, poly1, poly0, RSCtemp);
    float pint1 = p4 - pintcalc;
    float pint2calc = polyeq(span3, span2, span1, span0, RSCtemp);
    float pint2 = pint1 / pint2calc;
    float RSCpcompfs = polyeq(shape3, shape2, shape1, shape0, pint2);
    RSCpcomp = (RSCpcompfs * prange) + pminimum;
    RSCpcomp -= RSCoffset;

    HSCaverage += HSCpressure;
    RSCaverage += RSCpcomp;

    //Serial.print("                           HSC pressure = "); Serial.print(HSCpressure, 4); Serial.println(" PSI");
    //Serial.println("");
    //Serial.print("              RSC Pressure differential = "); Serial.print(RSCpcomp, 4); Serial.println(" inH2O");
    //delay(50);
  }

  HSCaverage /= noaverages;
  RSCaverage /= noaverages;

  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.println("");
  if (HSCstatus > 0) {
    Serial.print("                             HSC STATUS WARNING = "); Serial.println(HSCstatus);
    Serial.println("");
  }
  Serial.println("");
  Serial.println("");
  Serial.print("                            Temperature = "); Serial.print(HSCtemp2); Serial.println(" degrees C");
  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.print("                           HSC pressure = "); Serial.print(HSCpressure, 4); Serial.println(" PSI");
  Serial.println("");
  Serial.print("                   HSC pressure AVERAGE = "); Serial.print(HSCaverage, 4); Serial.println(" PSI");
  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.print("              RSC Pressure differential = "); Serial.print(RSCpcomp, 4); Serial.println(" inH2O");
  Serial.println("");
  Serial.print("      RSC Pressure differential AVERAGE = "); Serial.print(RSCaverage, 4); Serial.println(" inH2O");
  Serial.println("");

  //delay(1000);
  
}

float readfloat() {
  union u_tag {
    byte b[4];
    float fval;
  } u;
  u.b[0] = SPI.transfer(0);
  u.b[1] = SPI.transfer(0);
  u.b[2] = SPI.transfer(0);
  u.b[3] = SPI.transfer(0);
  float result = u.fval;
  return result;
}

float polyeq (float coeff1, float coeff2, float coeff3, float coeff4, float temp) {
  float result = coeff1 * pow(temp, 3) + coeff2 * pow(temp, 2) + coeff3 * temp + coeff4;
  return result;
}

Hi, did you ever did manage to get the RSC sensors working a reasonable sample rate? If you did, I would be very interested in the code! Thanks.

The SPI Protocol says that the data being exchanged between Master and Slave should be read out whether they are needed or not. Now, rerun your sketcht with the following modifications of the code lines and commenting out the delay(). If it works (and should work), report it and then we will explain the significance of the stated rule if you still desire.

    byte x1 = SPI.transfer(68); //write to register 1
    //delay(50);
    byte x2 = SPI.transfer(4);  //pressure mode
    //delay(100); //needs to be >10??
    byte x3 = SPI.transfer(8);  //start conversion
    //delay(100);

Thanks Golam! I'll give it a try and post the results.

The code as described indeed gives good results! The only delay that needs to be implemented is the one specified in the datasheet as necessary for the conversion rate. (In the code below the highest sample rate of 2kHz is used, 0.51 ms delay should be enough)

// Read pressure
  x1 = SPI.transfer(68); // write 1 byte to register 1 [0100 0100]
  x2 = SPI.transfer(212);  // pressure mode [1101 0100]
  x3 = SPI.transfer(8);  // start conversion
  delay(1);

  p1 = SPI.transfer(0);
  p2 = SPI.transfer(0);
  p3 = SPI.transfer(0);

Full code

#include <SPI.h>
#include <math.h>

// Pins
int DRDY      =  4;
int CSEE      =  2;
int CSADC     =  3;

float offset = 0.0;
float average = 0.0;

int i = 0;
int j = 0;

float pcomp = 0.0;

unsigned char  ADCconfig1 = 0;
unsigned char  ADCconfig2 = 0;
unsigned char  ADCconfig3 = 0;
unsigned char  ADCconfig4 = 0;

float poly0 = 0.0;
float poly1 = 0.0;
float poly2 = 0.0;
float poly3 = 0.0;

float shape0 = 0.0;
float shape1 = 0.0;
float shape2 = 0.0;
float shape3 = 0.0;

float span0 = 0.0;
float span1 = 0.0;
float span2 = 0.0;
float span3 = 0.0;

float prange = 0.0;
float pminimum = 0.0;
char pref;

float pintcalc = 0.0;
float pint1 = 0.0;
float pint2calc = 0.0;
float pint2 = 0.0;
float pcompfs = 0.0;

byte pu1;
byte pu2;
byte pu3;
byte pu4;
byte pu5;

byte x1;
byte x2;
byte x3;

int32_t p1;
int32_t p2;
int32_t p3;

int32_t T_raw;
float T;

int32_t T1;
int32_t T2;
int32_t T3;

union sfp24bit {
  byte b[4];
  long result;
} tval;

union u_tag {
  byte b[4];
  float fval;
} u;

float result = 0.0;

void setup() {

  pinMode (CSEE, OUTPUT);
  pinMode (CSADC, OUTPUT);
  digitalWrite(CSADC, HIGH);
  digitalWrite(CSEE, HIGH);

  // Set data rate for serial monitor
  Serial.begin(115200);

  // Initialize SPI on EEPROM
  SPI.begin();
  SPI.beginTransaction(SPISettings(1250000, MSBFIRST, SPI_MODE0));

  // 1. Read the ADC settings and the compensation values from EEPROM.
  digitalWrite(CSEE, LOW);

  // Pressure range
  SPI.transfer16(795); //read from address 27
  prange = readfloat();
  pminimum = readfloat();

  // Pressure units
  pu1 = SPI.transfer(0);
  pu2 = SPI.transfer(0);
  pu3 = SPI.transfer(0);
  pu4 = SPI.transfer(0);
  pu5 = SPI.transfer(0);
  char punits [] = {pu1, pu2, pu3, pu4, pu5};

  // Pressure ref
  pref = SPI.transfer(0);

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  // ADC configuration
  SPI.transfer16(829); //start reading byte 61 (ADC config settings)
  ADCconfig1 = SPI.transfer(0); 
  SPI.transfer(0);
  ADCconfig2 = SPI.transfer(0);
  SPI.transfer(0);
  ADCconfig3 = SPI.transfer(0);
  SPI.transfer(0);
  ADCconfig4 = SPI.transfer(0);

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  // Polynomial coefficients 130 to 145
  SPI.transfer16(898); //start reading byte 130 (Polynomial Coefficients)
  poly0 = readfloat();
  poly1 = readfloat();
  poly2 = readfloat();
  poly3 = readfloat();

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  // Span coefficients 210 to 225
  SPI.transfer16(978); //start reading byte 210
  span0 = readfloat();
  span1 = readfloat();
  span2 = readfloat();
  span3 = readfloat();

  digitalWrite(CSEE, HIGH);
  digitalWrite(CSEE, LOW);

  // Shape coefficients 290 to 305
  SPI.transfer16(2850); //start reading byte 290
  shape0 = readfloat();
  shape1 = readfloat();
  shape2 = readfloat();
  shape3 = readfloat();

  digitalWrite(CSEE, HIGH);

  //2. Initialize the ADC converter using the settings provided in EEPROM.
  SPI.endTransaction();
  SPI.beginTransaction(SPISettings(1250000, MSBFIRST, SPI_MODE1));
  SPI.begin();

  digitalWrite(CSADC, LOW);
  SPI.transfer(6);          // reset ADC
  SPI.transfer(67);         // write 4 bytes starting at reg 0 [0100 0011] = 67
  SPI.transfer(ADCconfig1);
  SPI.transfer(ADCconfig2);
  SPI.transfer(ADCconfig3);
  SPI.transfer(ADCconfig4);
  digitalWrite(CSADC, HIGH);
  
}

void loop() {

  // Read temperature
  digitalWrite(CSADC, LOW);
  delay(1);
  
  x1 = SPI.transfer(68); // write 1 byte to register 1 [0100 0100]
  x2 = SPI.transfer(214);  // set ADC to temperature mode [1101 0110]
  x3 = SPI.transfer(8);  // start conversion
  delay(1);
  
  T1 = SPI.transfer(0);
  T2 = SPI.transfer(0);
  T3 = SPI.transfer(0);

  int32_t T_raw = ((T1 << 8) | T2) >> 2; // disregard last 10 of 24 bits (all 8 from T3 and 2 from T2)
  float T = T_raw * 0.03125;
  
  // Read pressure
  x1 = SPI.transfer(68); // write 1 byte to register 1 [0100 0100]
  x2 = SPI.transfer(212);  // pressure mode [1101 0100]
  x3 = SPI.transfer(8);  // start conversion
  delay(1);
  
  p1 = SPI.transfer(0);
  p2 = SPI.transfer(0);
  p3 = SPI.transfer(0);
  
  digitalWrite(CSADC, HIGH);
  
  int32_t p_raw = (p1 << 24) | (p2 << 16) | (p3 << 8);
  p_raw /= 256;
  
  pintcalc   = polyeq(poly3, poly2, poly1, poly0, T_raw);
  pint1      = p_raw - pintcalc;
  pint2calc  = polyeq(span3, span2, span1, span0, T_raw);
  pint2      = pint1 / pint2calc;
  pcompfs = polyeq(shape3, shape2, shape1, shape0, pint2);
  pcomp   = (pcompfs * prange) + pminimum;
  pcomp  -= offset;

  // Show example output
  Serial.print(T); Serial.print("\t");
  Serial.print(prange); Serial.print("\t");
  Serial.print(pminimum); Serial.print("\t");
  Serial.print(pcompfs); Serial.print("\t");
  Serial.print(pcomp, 4); Serial.println(" mbar");
  delay(100);

}

float readfloat() {
  union u_tag {
    byte b[4];
    float fval;
  } u;
  u.b[0] = SPI.transfer(0);
  u.b[1] = SPI.transfer(0);
  u.b[2] = SPI.transfer(0);
  u.b[3] = SPI.transfer(0);
  float result = u.fval;
  return result;
}

float polyeq (float coeff1, float coeff2, float coeff3, float coeff4, float temp) {
  result = coeff1 * pow(temp, 3) + coeff2 * pow(temp, 2) + coeff3 * temp + coeff4;
  return result;
}

Thanks for your input GolamMostafa!

MVANNESSELROOIJ:
Thanks for your input GolamMostafa!

You are welcome!

Cheers!