MAX17205 Battery Gauge Driver
The max17205.c module implements the I2C driver for communicating with the Maxim Integrated MAX17205 battery fuel gauge IC.
Features
- Voltage Measurement: Uses a 1.25mV LSB scaling from the
BATTregister. - Current Measurement: Extracts both instantaneous and device-averaged current from the
CURRENTandAVGCURRENTregisters. - State of Charge (SOC): Provides a precise percentage based on the ModelGauge m5 algorithm from the
REPSOCregister. - Capacity: Retrieves remaining capacity in mAh.
- Time Estimates: Retrieves Time-to-Empty (TTE) and Time-to-Full (TTF) estimations.
Initialization
The max17205_init function configures the device parameters according to the specific battery pack size (design_capacity_mah) and the shunt resistor (rsense_mohm):
- It calculates and writes to the
DesignCapregister using the primary I2C address (0x36). - It calculates and writes to the
nRSenseregister using the extended I2C address (0x0B).
Hardware Interface
Communication is strictly via the STM32 HAL I2C API (HAL_I2C_Mem_Read and HAL_I2C_Mem_Write). The driver implements separate helpers for primary and extended I2C address spaces required by the MAX17205's register layout.
