diff --git a/docs/power.md b/docs/power.md index 2cc5bf4f..55990636 100644 --- a/docs/power.md +++ b/docs/power.md @@ -240,6 +240,11 @@ unnecessary idle draw that affect all nRF52 boards (not only SenseCAP Solar): - **Disconnect GPS UART pins while GPS is off**: `NmeaGpsDriver::stopHardware()` now resets the UART TX/RX pins via `nrf_gpio_cfg_default()` after `Uart::end()`, preventing back-powering of the unpowered GPS receiver through GPIO/ESD paths. +- **Disable unused I2C bus & lower noise-floor calibration rate**: on nRF52, + `EnvironmentSensorManager::begin()` calls `Wire.end()` when the I2C bus scan + finds zero devices (re-enabling temporarily for the `i2c` CLI command). + `NOISE_FLOOR_CALIB_INTERVAL` is raised from 2 s to 10 s to cut idle SPI + wake-ups 5x. ## Measuring this yourself — two traps diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index b3270d6a..14ad28d9 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -13,7 +13,7 @@ namespace mesh { #define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX #ifndef NOISE_FLOOR_CALIB_INTERVAL - #define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds + #define NOISE_FLOOR_CALIB_INTERVAL 10000 // 10 seconds #endif void Dispatcher::begin() { diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 8d8b8dbe..950328e6 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -8,6 +8,10 @@ #define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors #endif +#ifdef NRF52_PLATFORM +static bool telem_wire_stopped = false; +#endif + // ============================================================ // Sensor library includes and static driver instances // ============================================================ @@ -715,6 +719,11 @@ bool EnvironmentSensorManager::begin() { bool detected[128] = {}; scanI2CBus(TELEM_WIRE, detected); + bool any_i2c_device = false; + for (uint8_t addr = 0x08; addr < 0x78; addr++) { + if (detected[addr]) { any_i2c_device = true; break; } + } + // Walk the sensor table and initialize only detected devices. _active_sensor_count = 0; for (size_t i = 0; i < SENSOR_TABLE_SIZE && _active_sensor_count < MAX_ACTIVE_SENSORS; i++) { @@ -741,6 +750,15 @@ bool EnvironmentSensorManager::begin() { } } +#ifdef NRF52_PLATFORM + if (!any_i2c_device) { + // No device ACKed anywhere on the bus (neither sensor nor RTC/display): + // disable TWIM to avoid idle peripheral/pull-up draw. + (TELEM_WIRE)->end(); + telem_wire_stopped = true; + } +#endif + return true; } @@ -765,6 +783,13 @@ static size_t appendWhole(char* dest, size_t used, size_t max_len, const char* s } int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) { +#ifdef NRF52_PLATFORM + bool restarted = telem_wire_stopped; + if (restarted) { + (TELEM_WIRE)->begin(); + telem_wire_stopped = false; + } +#endif bool found[128] = {}; scanI2CBus(TELEM_WIRE, found); @@ -790,6 +815,13 @@ int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) { n++; } +#ifdef NRF52_PLATFORM + if (restarted && n == 0) { + (TELEM_WIRE)->end(); + telem_wire_stopped = true; + } +#endif + if (n == 0) { used = appendWhole(dest, 0, max_len, "no I2C device answered"); }