XGZP6859D Pressure Sensor with Stm32f302R8

170 Views Asked by At

I want to create an API to get value from XGZP6859D pressure sensor using the stm32f302r8 nucleo board,

Here's its datasheet http://cfsensor.com/static/upload/file/20210110/XGZP6859D%20Pressure%20Sensor%20Module.pdf.

I wrote all the register in the API, and I declared a function that will help to get the pressure value from the sensor.

Would anyone help me or give some tips how can write the function? Thanks in advance.

1

There are 1 best solutions below

0
On

Here's what the documentation says:

I2C Device Address:0X6D

  1. Read the 0xA5 register value, put the read binary value "and" on "11111111101" then write to 0xA5.
  2. Send instructions 0x0A to 0x30 register for one temperature acquisition, one pressure data acquisition.
  3. Read the 0x30 register address. If Sco bit is 0,signify the acquisition end, the data can be read.
  4. Read 0x06, 0x07, 0x08 register address data to form a 24-bit AD value (pressure data AD value)

Assuming you have some basic i2c read/write functionality and the i2c address of 0X6D, a pressure read sudo-function would look something like this:

// 1
i2cSensorAddress = 0x6D; // Make sure you address the sensor properly
int8_t reg = i2cSensorRead(0xA5);
i2cSensorWrite(0xA5, reg & 0xFD); //11111101 in hex

// 2
i2cSensorWrite(0x30, 0x0A);

// 3
while (!(i2cSensorRead(0x30) & 0x08)) { // Wait for transaction (SCO is bit 3)
    sleep();
}

// 4
int32_t pressureData = 0;
int8_t dataAddr = 0x06;
for(int i = 0; i < 3; i++){
    pressureData = pressureData << 8;
    pressureData |= i2cSensorRead(dataAddr++);
}

return pressureData;
        

Hope that points you in the right direction! Good luck