diff --git a/src/drivers/magnetometer/akm/ak09916/AK09916.cpp b/src/drivers/magnetometer/akm/ak09916/AK09916.cpp index 613d9e184d..51f241a01b 100644 --- a/src/drivers/magnetometer/akm/ak09916/AK09916.cpp +++ b/src/drivers/magnetometer/akm/ak09916/AK09916.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2019-2020 PX4 Development Team. All rights reserved. + * Copyright (c) 2019-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -87,21 +87,23 @@ void AK09916::print_status() int AK09916::probe() { - const uint8_t WIA1 = RegisterRead(Register::WIA1); + for (int retry = 0; retry < 3; retry++) { + const uint8_t WIA1 = RegisterRead(Register::WIA1); + const uint8_t WIA2 = RegisterRead(Register::WIA2); - if (WIA1 != Company_ID) { - DEVICE_DEBUG("unexpected WIA1 0x%02x", WIA1); - return PX4_ERROR; + if ((WIA1 == Company_ID) && (WIA2 == Device_ID)) { + _retries = 1; + return PX4_OK; + + } else if (WIA1 != Company_ID) { + DEVICE_DEBUG("unexpected WIA1 0x%02x", WIA1); + + } else if (WIA2 != Device_ID) { + DEVICE_DEBUG("unexpected WIA2 0x%02x", WIA2); + } } - const uint8_t WIA2 = RegisterRead(Register::WIA2); - - if (WIA2 != Device_ID) { - DEVICE_DEBUG("unexpected WIA2 0x%02x", WIA2); - return PX4_ERROR; - } - - return PX4_OK; + return PX4_ERROR; } void AK09916::RunImpl() diff --git a/src/drivers/magnetometer/akm/ak8963/AK8963.cpp b/src/drivers/magnetometer/akm/ak8963/AK8963.cpp index 8055f76149..da0db41aca 100644 --- a/src/drivers/magnetometer/akm/ak8963/AK8963.cpp +++ b/src/drivers/magnetometer/akm/ak8963/AK8963.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2020 PX4 Development Team. All rights reserved. + * Copyright (c) 2020-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -87,14 +87,19 @@ void AK8963::print_status() int AK8963::probe() { - const uint8_t WIA = RegisterRead(Register::WIA); + for (int retry = 0; retry < 3; retry++) { + const uint8_t WIA = RegisterRead(Register::WIA); - if (WIA != Device_ID) { - DEVICE_DEBUG("unexpected WIA 0x%02x", WIA); - return PX4_ERROR; + if (WIA == Device_ID) { + _retries = 1; + return PX4_OK; + + } else { + DEVICE_DEBUG("unexpected WIA 0x%02x", WIA); + } } - return PX4_OK; + return PX4_ERROR; } void AK8963::RunImpl() diff --git a/src/drivers/magnetometer/bosch/bmm150/BMM150.cpp b/src/drivers/magnetometer/bosch/bmm150/BMM150.cpp index d761ae513f..bd61c6160f 100644 --- a/src/drivers/magnetometer/bosch/bmm150/BMM150.cpp +++ b/src/drivers/magnetometer/bosch/bmm150/BMM150.cpp @@ -86,17 +86,19 @@ void BMM150::print_status() int BMM150::probe() { // 3 retries - for (int i = 0; i < 3; i++) { + for (int retry = 0; retry < 3; retry++) { const uint8_t POWER_CONTROL = RegisterRead(Register::POWER_CONTROL); const uint8_t CHIP_ID = RegisterRead(Register::CHIP_ID); PX4_DEBUG("POWER_CONTROL: 0x%02hhX, CHIP_ID: 0x%02hhX", POWER_CONTROL, CHIP_ID); if (CHIP_ID == chip_identification_number) { + _retries = 1; return PX4_OK; } else if ((CHIP_ID == 0) && !(POWER_CONTROL & POWER_CONTROL_BIT::PowerControl)) { // in suspend Chip ID read (register 0x40) returns “0x00” (I²C) or high-Z (SPI). + _retries = 1; return PX4_OK; } } diff --git a/src/drivers/magnetometer/isentek/ist8310/IST8310.cpp b/src/drivers/magnetometer/isentek/ist8310/IST8310.cpp index c329542666..8117d0b52b 100644 --- a/src/drivers/magnetometer/isentek/ist8310/IST8310.cpp +++ b/src/drivers/magnetometer/isentek/ist8310/IST8310.cpp @@ -86,10 +86,10 @@ void IST8310::print_status() int IST8310::probe() { for (int retry = 0; retry < 3; retry++) { - const uint8_t WAI = RegisterRead(Register::WAI); if (WAI == Device_ID) { + _retries = 1; return PX4_OK; } else { diff --git a/src/drivers/magnetometer/qmc5883l/QMC5883L.cpp b/src/drivers/magnetometer/qmc5883l/QMC5883L.cpp index 5da9accaa6..1976b24588 100644 --- a/src/drivers/magnetometer/qmc5883l/QMC5883L.cpp +++ b/src/drivers/magnetometer/qmc5883l/QMC5883L.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2020 PX4 Development Team. All rights reserved. + * Copyright (c) 2020-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -87,7 +87,7 @@ int QMC5883L::probe() { _retries = 1; - for (int i = 0; i < 3; i++) { + for (int retry = 0; retry < 3; retry++) { // first read 0x0 once const uint8_t cmd = 0; uint8_t buffer{}; diff --git a/src/drivers/magnetometer/vtrantech/vcm1193l/VCM1193L.cpp b/src/drivers/magnetometer/vtrantech/vcm1193l/VCM1193L.cpp index 1767e2b27a..e419962855 100644 --- a/src/drivers/magnetometer/vtrantech/vcm1193l/VCM1193L.cpp +++ b/src/drivers/magnetometer/vtrantech/vcm1193l/VCM1193L.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2021 PX4 Development Team. All rights reserved. + * Copyright (c) 2021-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -87,7 +87,7 @@ int VCM1193L::probe() { _retries = 1; - for (int i = 0; i < 3; i++) { + for (int retry = 0; retry < 3; retry++) { // first read 0x0 once const uint8_t cmd = 0; uint8_t buffer{};