Can't read the pressure sensor value in SPI mode

I'm using a sensor WF100DPZ for pressure measurement with arduino UNO in SPI mode. Here's the code:

#include <SPI.h>

const int chipSelectPin = 10; // Choose the appropriate digital pin for chip select

void setup() {
  Serial.begin(9600);

  SPI.begin();
  pinMode(chipSelectPin, OUTPUT);

  // Wake up the sensor
  digitalWrite(chipSelectPin, LOW);
  delay(10);
  digitalWrite(chipSelectPin, HIGH);

  // Wait for the sensor to stabilize
  delay(1000);

  // Set SDO mode (4-wire SPI, LSB first)
  setSDOMode(0);

  // Read and print the Part ID
  byte partID = readPartID();
  Serial.print("Part ID: 0x");
  Serial.println(partID, HEX);
}

void loop() {
  // Read the Data registers
  int dataMSB = readRegister(0x06);
  int dataCSB = readRegister(0x07);
  int dataLSB = readRegister(0x08);

  // Read the Temperature registers
  int tempMSB = readRegister(0x09);
  int tempLSB = readRegister(0x0A);

  // Combine the MSB, CSB, and LSB values
  long rawData = ((long)dataMSB << 16) | ((long)dataCSB << 8) | dataLSB;
  int rawTemperature = (tempMSB << 8) | tempLSB;


  // Start pressure measurement
  startPressureMeasurement();

  if (readRegister(0x02) & 0x01) {
    // Read the final converted value from SCO
    int measurementValue = readMeasurementValue();
    Serial.print("Final Converted Value from SCO: ");
    Serial.println(measurementValue);
  } else {
    Serial.println("Error: Data not ready.");
  }

  // Wait for a moment before reading again
  delay(1000);
}

void setSDOMode(byte sdoMode) {
  // Select the sensor
  digitalWrite(chipSelectPin, LOW);

  // Send the command to set SDO mode
  SPI.transfer(0x00); // SPI_Ctrl register address
  SPI.transfer(sdoMode << 7); // Set the SDO mode

  // Deselect the sensor
  digitalWrite(chipSelectPin, HIGH);
}

byte readPartID() {
  // Select the sensor
  digitalWrite(chipSelectPin, LOW);

  // Send the command to read Part ID
  SPI.transfer(0x01); // Part_ID register address

  // Read the Part ID
  byte partID = SPI.transfer(0);

  // Deselect the sensor
  digitalWrite(chipSelectPin, HIGH);

  return partID;
}

int readRegister(byte regAddr) {
  // Select the sensor
  digitalWrite(chipSelectPin, LOW);

  // Send the command to read from the specified register
  SPI.transfer(regAddr);

  // Read the register value
  int regValue = SPI.transfer(0);

  // Deselect the sensor
  digitalWrite(chipSelectPin, HIGH);

  return regValue;
}

void startPressureMeasurement() {
  // Select the sensor
  digitalWrite(chipSelectPin, LOW);

  // Send the command to start pressure measurement (CMD register address)
  SPI.transfer(0x30); // CMD register address
  SPI.transfer(0x18); // Set sleep_time to 0001 (62.5ms) and measurement_control to 00b (single shot pressure measurement)
  SPI.transfer(0x01); // Set SCO to 1 to start conversion

  // Deselect the sensor
  digitalWrite(chipSelectPin, HIGH);
}

int readMeasurementValue() {
  // Select the sensor
  digitalWrite(chipSelectPin, LOW);

  // Send the command to read measurement value
  SPI.transfer(0x06); // DATA_MSB register address

  // Read the measurement value
  int measurementValue = (SPI.transfer(0) << 16) | (SPI.transfer(0) << 8) | SPI.transfer(0);

  // Deselect the sensor
  digitalWrite(chipSelectPin, HIGH);

  return measurementValue;
}

here's the circuit:

and here's the datasheet:
WF100D 规格书.pdf (1.4 MB)

the serial monitor shows:
image

where am I wrong?

Your image shows the sensor connected to I2C and not SPI.
I2C Pins A4 and A5
SPI pins 11,12,13 and CS 10.

" SPI - Arduino Reference

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.