TroubleshootingGravity

Reading Registers from Gravity Electrochemical Oxygen Sensor I2C with STM32

userHead jlaufer 2025-05-31 06:14:29 566 Views0 Replies

Hello! I am writing STM32 drivers to communicate with the Gravity Electrochemical Oxygen Sensor

 

I tried to follow the Arduino code directly but was having an issue since reading register 0x03 (OXYGEN_DATA_REGISTER) using I2C with STM32 returns a static register which doesn't change with varying oxygen levels. I ended up just looking at all the registers available on the O2 sensor using the below code. It appears that there were 40 registers available on the O2 sensor

    uint8_t start_reg = 0x00; // Start at register 0

    uint8_t buffer[256] = {0}; // Read up to 256 registers (adjust as needed)

    // Write the starting register address

    HAL_I2C_Master_Transmit(_hi2c, _address << 1, &start_reg, 1, 100);

    // Read a block of registers

    HAL_I2C_Master_Receive(_hi2c, _address << 1, buffer, 256, 100)

 

I was able to pinpoint buffer[16], buffer[17], and buffer[18] as the registers which contain the oxygen values since these are the only registers that change with varying oxygen levels. These registers seem like reasonable raw data values since in ambient air the formula buffer[16] + buffer[17]/10 + buffer[18] / 100 = 20.76% makes sense. However, is this a calibrated reading? 

 

When I recalibrated the sensor in ambient air to test which registers are touched by calibration - buffer[19], buffer[20], buffer[21], buffer[25], buffer[26], buffer[29], buffer[30] also changed. I know that according to the Arduino code, the _Key (oxygen reading multiplier) is calculated by reading the GET_KEY_REGISTER and applying the below formula/logic in Arduino.

 

if(value == 0){
   this->_Key = 20.9 / 120.0;
 }else{
   this->_Key = (float)value / 1000.0;
}

 

In this case, reading and calculating buffer indices 16, 17, 18 appear to give a reasonable value without any additional multiplier, but if this isn't a calibrated value, how do I adjust for the calibration using these registers?