diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.cpp index 20ce5b85b7..070c233995 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.cpp @@ -52,6 +52,9 @@ extern const AP_HAL::HAL& hal; #define HAL_BATTMON_INA2XX_ADDR 0 #endif +// list of addresses to probe if I2C_ADDR is zero +const uint8_t AP_BattMonitor_INA2XX::i2c_probe_addresses[] { 0x41, 0x44, 0x45 }; + const AP_Param::GroupInfo AP_BattMonitor_INA2XX::var_info[] = { // @Param: I2C_BUS @@ -64,7 +67,7 @@ const AP_Param::GroupInfo AP_BattMonitor_INA2XX::var_info[] = { // @Param: I2C_ADDR // @DisplayName: Battery monitor I2C address - // @Description: Battery monitor I2C address + // @Description: Battery monitor I2C address. If this is zero then probe list of supported addresses // @Range: 0 127 // @User: Advanced // @RebootRequired: True @@ -234,6 +237,11 @@ bool AP_BattMonitor_INA2XX::detect_device(void) WITH_SEMAPHORE(dev->get_semaphore()); + if (i2c_address.get() == 0) { + dev->set_address(i2c_probe_addresses[i2c_probe_next]); + i2c_probe_next = (i2c_probe_next+1) % sizeof(i2c_probe_addresses); + } + if (read_word16(REG_228_MANUFACT_ID, id) && id == 0x5449 && read_word16(REG_228_DEVICE_ID, id) && (id&0xFFF0) == 0x2280) { return configure(DevType::INA228); diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.h b/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.h index c58cecb57f..ca1b7c69d5 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.h @@ -37,6 +37,9 @@ private: INA238, }; + static const uint8_t i2c_probe_addresses[]; + uint8_t i2c_probe_next; + bool configure(DevType dtype); bool read_word16(const uint8_t reg, int16_t& data) const; bool read_word24(const uint8_t reg, int32_t& data) const;