A firmware-level battery monitoring system built on the BQ79600 (Bridge) and BQ79616 (Slaves) ICs, communicating with an STM32 MCU over UART.
- System Overview
- Communication Interface
- Initialization
- Cell Voltage Configuration
- Cell Voltage Reading
- GPIO & Temperature Configuration
- GPIO Voltage Reading
- Fault Handling
- System Flow Summary
The system performs battery monitoring using the following hardware:
| Component | Role | Connection |
|---|---|---|
| BQ79600 | Bridge | Connected to STM32 MCU |
| BQ79616 | Slaves (×N) | Daisy-chained to Bridge |
The Bridge interfaces with the MCU on one side and connects to multiple slave devices in a daisy-chain topology on the other. Each slave is connected in series to the next.
Reference: Section 7.3.1.3 — SPI/UART Selection | Section 5 — Pin Configuration and Functions
Two communication methods are supported between the MCU and the Bridge:
- SPI
- UART ✅ (selected in this design)
Selected Configuration: UART at 1 Mbps baud rate.
The initialization phase must follow proper hardware setup and covers:
- Wake-up sequence
- Auto-addressing
- Cell voltage configuration
- GPIO configuration
Reference: Section 7.3.1.2 — Pings
The wake-up procedure is as follows:
-
Deinitialize UART:
UART_DeInit(); -
Configure the TX pin as GPIO.
-
Drive the TX pin LOW for approximately 2.5 ms (this value is not strict and can be adjusted).
-
Reinitialize UART:
UART_Init();
After wake-up, communication continues normally using UART frames.
Reference: Section 7.3.2 — Communication
Reference: Section 7.3.2.3.1 — Auto-Addressing
Auto-addressing assigns a unique address to each device on the bus:
- The Bridge (BQ79600)
- Each Slave (BQ79616)
Addresses are assigned sequentially starting from 0.
Reference: Section 9.3.2.1.1 — Cell Voltage Measurements
Not all 16 cells are required to be active. Configure the number of active cells using:
| Parameter | Value |
|---|---|
| Register | ACTIVE_CELL |
| Page | 128 |
Set overvoltage and undervoltage protection thresholds:
| Parameter | Value |
|---|---|
| Registers | OV_THRESH, UV_THRESH |
| Page | 160 |
Reference: Section 9.3.4.1 — OVUV Protectors
Configure the operating mode for OV/UV monitoring:
- Continuous mode
- One-shot mode
| Parameter | Value |
|---|---|
| Register | OVUV_CTRL |
| Page | 161 |
Reference: Section 9.3.4.1.2 — OVUV Control and Status
Verify that OV/UV monitoring is active:
| Parameter | Value |
|---|---|
| Register | DEV_STAT[OVUV_RUN] |
| Page | 135 |
Reference: Section 9.5.4.6 — ADC Measurement Results (Page 140)
Each measurement is 16-bit, composed of:
- High byte
- Low byte
Voltage (V) = ADC_Value × VLSB_ADC
Where:
VLSB_ADC = 0.00019073 V/LSB
Reference: ADC Resolution (Page 14)
uint8_t readBoardVoltages(uint8_t boardNum,
uint8_t numCells,
int *totalV,
uint16_t *cellVoltages);All cell voltage readings from all slave boards are stored in a 2D array:
uint16_t cellVoltages_board[SLAVEBOARDS][16];Reference: Section 9.3.2.1.2 — Temperature Measurements
GPIO pins support the following operating modes:
| Mode | Description |
|---|---|
| Digital Input | Standard logic input |
| Digital Output | Standard logic output |
| ADC Only | Analog measurement only |
| ADC + OT/UT | ✅ Used in this design |
Set over-temperature and under-temperature protection thresholds:
| Parameter | Value |
|---|---|
| Register | OTUT_THRESH |
| Page | 161 |
Reference: Section 9.3.4.2 — OTUT Protector
| Parameter | Value |
|---|---|
| Register | OTCB_THRESH |
Enable the internal reference voltage for temperature sensors:
| Parameter | Value |
|---|---|
| Register | CONTROL2[TSREF_EN] |
| Page | 132 |
Reference: Section 9.3.1.6 — TSREF
Function: Provides a 5V output to power temperature sensors. The ground reference is taken from the same slave board.
Set all relevant GPIOs to ADC + OT/UT mode using the following registers:
| Register | Page |
|---|---|
GPIO_CONF1 |
162 |
GPIO_CONF2 |
162 |
GPIO_CONF3 |
162 |
GPIO_CONF4 |
162 |
Reference: Section 9.5.4.9 — GPIO Configuration
Configure the operating mode for OT/UT monitoring:
- Continuous mode
- One-shot mode
| Parameter | Value |
|---|---|
| Register | OTUT_CTRL |
| Page | 161 |
Reference: Section 9.3.4.2.2 — OTUT Control and Status
Verify that OT/UT monitoring is active:
| Parameter | Value |
|---|---|
| Register | DEV_STAT[OTUT_RUN] |
| Page | 135 |
Reference: Section 9.5.4.6 — ADC Measurement Results
Voltage (V) = ADC_Value × VLSB_DIAG
Where:
VLSB_DIAG = 152.59 µV/LSB
Reference: Electrical Characteristics (Page 15)
float readGPIOVoltage(uint8_t BID,
uint8_t GPIO_NUM,
uint16_t *raw_value_ptr);After completing cell voltage and temperature monitoring, the system must detect and respond to faults.
| Fault | Description |
|---|---|
| OV | Over Voltage |
| UV | Under Voltage |
| OT | Over Temperature |
| UT | Under Temperature |
- Read fault status registers
- Identify the fault type
- Take appropriate action based on severity:
- 🔴 Shutdown — critical fault, halt operation
- 🟡 Warning — non-critical, alert the system
- 📋 Logging — record the event for diagnostics
The complete system execution flow proceeds as follows:
1. Hardware Setup
↓
2. Initialization
├── Wake-Up Sequence
└── Auto-Addressing
↓
3. Cell Voltage Configuration
├── Active Cell Selection
├── OV/UV Threshold Setup
├── OV/UV Control Mode
└── Status Verification
↓
4. Cell Voltage Reading
↓
5. GPIO / Temperature Configuration
├── OT/UT Threshold Setup
├── Comparator Threshold
├── TSREF Enable
├── GPIO Mode Configuration
├── OT/UT Control Mode
└── Status Verification
↓
6. Temperature Reading
↓
7. Fault Detection & Handling