Your device's battery life is 10x worse than calculated — how do you debug it?
A 10x discrepancy between calculated and actual battery life almost always means the device is not reaching its lowest power state, or something is drawing current that your power budget did not account for. The debugging approach is methodical current measurement combined with elimination of potential leakage sources.
Step 1 — Measure the actual sleep current. Connect a power analyzer (PPK2, Joulescope, or shunt resistor with oscilloscope) and put the device into its deepest sleep mode. Compare the measured sleep current against the MCU datasheet's specification for that mode. If the MCU datasheet says 2 microamps in Stop mode but you measure 500 microamps, the MCU itself is not fully asleep. Common causes: a peripheral clock was left enabled (a single enabled UART peripheral can draw 100+ microamps), the debug probe is still connected (JTAG/SWD keeps the debug domain powered, adding 500 microamps or more on many STM32 parts), the PLL or HSE oscillator was not shut down, or the voltage regulator is in main mode instead of low-power mode.
Step 2 — Check GPIOs. Floating (unconnected) GPIO pins are the most common hidden current drain. If an input pin is floating near the threshold voltage, the input buffer's CMOS transistors are both partially on, creating a shoot-through current of 10-100 microamps per pin. Multiply by 20 floating pins and you have milliamps. The fix: configure all unused GPIOs as analog inputs (disables the digital input buffer) or drive them to a known level. Also check GPIOs connected to external circuits — a pin configured as push-pull output driving into a pull-up or pull-down resistor creates a DC current path.
Step 3 — Isolate external components. Measure current with external peripherals removed one at a time: sensors, voltage regulators, LEDs, pull-up resistor networks, level shifters. Many sensors have quiescent currents of 1-10 microamps that are not negligible in a microamp-level power budget. LDO regulators have quiescent currents ranging from 1 microamp (modern ultra-low-power parts) to 5 milliamps (older general-purpose parts) — this alone can explain a 10x discrepancy. Also check whether the sensor's I2C or SPI bus pull-ups are drawing current when the bus is idle — a 4.7K pull-up to 3.3V on an I2C line that is low during sleep draws 700 microamps.
Step 4 — Verify the duty cycle. If sleep current checks out but battery life is still poor, the device is spending more time awake than intended. Use a GPIO toggle at sleep entry/exit and measure the duty cycle on an oscilloscope. Common causes: a periodic interrupt waking the device more frequently than designed (a misconfigured RTC timer period), a sensor interrupt that fires repeatedly (a noisy accelerometer triggering motion interrupts), or a communication stack that retries failed transmissions with aggressive backoff.
Source: Debugging & Testing Q&A
