mpu9250: Do a reasonable post chip init validations, reporting errors

Check that the mpu9250's configured registers match the settings
   written to them. Attempt to fix any that do not up to 3 times.
   printing erros to the console on mismatches and returning
   faliure if after 3 attempts the any of the values are
   still wrong.
This commit is contained in:
David Sidrane
2017-07-08 15:37:46 +02:00
committed by Lorenz Meier
parent 7e293ab1d3
commit 3272cc62d4
+10 -9
View File
@@ -421,24 +421,25 @@ int MPU9250::reset()
write_checked_reg(MPUREG_ACCEL_CONFIG2, BITS_ACCEL_CONFIG2_41HZ);
uint8_t retries = 10;
uint8_t retries = 3;
bool all_ok = false;
while (retries--) {
bool all_ok = true;
while (!all_ok && retries--) {
// Assume all checked values are as expected
all_ok = true;
uint8_t reg;
for (uint8_t i = 0; i < MPU9250_NUM_CHECKED_REGISTERS; i++) {
if (read_reg(_checked_registers[i]) != _checked_values[i]) {
if ((reg = read_reg(_checked_registers[i])) != _checked_values[i]) {
write_reg(_checked_registers[i], _checked_values[i]);
PX4_ERR("Reg %d is:%d s/b:%d Tries:%d", _checked_registers[i], reg, _checked_values[i], retries);
all_ok = false;
}
}
if (all_ok) {
break;
}
}
return OK;
return all_ok ? OK : -EIO;
}
int