Hi o_o, the Z2 value to zero is a possible value, but in the "compensate_z" function it is checked and generates a `BMM150_OVERFLOW_OUTPUT` error. This is the function I'm referring to: /*!
* @brief This internal API is used to obtain the compensated
* magnetometer Z axis data(micro-tesla) in int16_t.
*/
int16_t compensate_z(int16_t mag_data_z, uint16_t data_rhall, const struct bmm150_dev *dev)
{
int32_t retval;
int16_t process_comp_z0;
int32_t process_comp_z1;
int32_t process_comp_z2;
int32_t process_comp_z3;
int16_t process_comp_z4;
if (mag_data_z != BMM150_ZAXIS_HALL_OVERFLOW_ADCVAL) {
if ((dev->trim_data.dig_z2 != 0) && (dev->trim_data.dig_z1 != 0)
&& (data_rhall != 0) && (dev->trim_data.dig_xyz1 != 0)) {
/*Processing compensation equations*/
process_comp_z0 = ((int16_t)data_rhall) - ((int16_t) dev->trim_data.dig_xyz1);
process_comp_z1 = (((int32_t)dev->trim_data.dig_z3) * ((int32_t)(process_comp_z0))) / 4;
process_comp_z2 = (((int32_t)(mag_data_z - dev->trim_data.dig_z4)) * 32768);
process_comp_z3 = ((int32_t)dev->trim_data.dig_z1) * (((int16_t)data_rhall) * 2);
process_comp_z4 = (int16_t)((process_comp_z3 + (32768)) / 65536);
retval = ((process_comp_z2 - process_comp_z1) / (dev->trim_data.dig_z2 + process_comp_z4));
/* saturate result to +/- 2 micro-tesla */
if (retval > BMM150_POSITIVE_SATURATION_Z) {
retval = BMM150_POSITIVE_SATURATION_Z;
} else {
if (retval < BMM150_NEGATIVE_SATURATION_Z)
retval = BMM150_NEGATIVE_SATURATION_Z;
}
/* Conversion of LSB to micro-tesla*/
retval = retval / 16;
} else {
retval = BMM150_OVERFLOW_OUTPUT;
}
} else {
/* Overflow condition*/
retval = BMM150_OVERFLOW_OUTPUT;
}
return (int16_t)retval;
}
... View more