This project implements a Battery Management System (BMS) interface using the Analog Devices ADBMS6822 IC, with the STM32F412RET MCU.
It handles communication with the daisy-chained ADBMS6830 over isoSPI, retrieves battery monitoring data, manages EEPROM over IΒ²C, monitors IVT sensor data via Classic CAN, and streams measurements to a Node-RED dashboard via UART.
The system is designed to:
- Communicate with a daisy-chained stack of ADBMS6830 devices.
- Perform wake-up, configuration, and data readout cycles.
- Handle CAN communication with an IVT sensor and charger.
- Store configuration or log data in an external EEPROM (via IΒ²C).
- Use periodic timers for scheduled tasks and delay measurements.
- Stream data over UART for real-time dashboards.
- MCU: STM32F412RETx
- Communication:
- SPI1 β Communication with ADBMS6822 (2 Mbps)
- CAN1 β Communication with POWERTRAIN network (1 Mbps)
- CAN2 β Communication with Battery Charger (125 Kbps)
- IΒ²C β EEPROM (24xx series)
- USART1 (DMA) β Data stream to Node-RED (230400 baud)
- Peripherals:
- TIM2, TIM5 β microsecond timers for delay functions
- TIM8 β periodic interrupt every 800 ms
- GPIO PC13 β user push button (external interrupt)
- β SPI communication with ADBMS6822 (includes wake-up and PEC handling)
- β Classic CAN communication (bxCAN)
- β EEPROM driver with RTOS-aware delay and locking
- β UART streaming to Node-RED dashboards
- β External interrupt handling for user button
- β Multiple periodic timers
- β CRC10/CRC15 calculation for PEC integrity checks
- Baud rate: 2 Mbps
- Mode: SPI Mode 3 (CPOL = 1, CPHA = 1)
- NSS: Controlled manually via GPIO (software chip select)
Wake-up example:
void bms_wakeupChain(void) {
for (uint8_t ic = 0; ic < TOTAL_IC; ic++) {
bms_csLow();
HAL_Delay(1);
bms_csHigh();
HAL_Delay(1);
}
}- Verify SPI mode and timing match ADBMS6822 datasheet.
- Ensure CS toggling meets wake-up timing specs.
- Validate CRC10/CRC15 functions.
- Confirm delay timers (
bms_delayUs,bms_delayMsActive) are accurate.
| Timer | Purpose | Interval |
|---|---|---|
| TIM2 | Delay functions (Β΅s) | Β΅s scale |
| TIM5 | Delay / wake-up counter | Β΅s scale |
| TIM8 | Periodic task scheduler | 800 ms |
Example configuration:
htim8.Instance = TIM8;
htim8.Init.Prescaler = 63999; // 64 MHz / 64000 = 1 kHz
htim8.Init.Period = 799; // 1 kHz / 800 = 1.25 Hz (~800 ms)
HAL_TIM_Base_Start_IT(&htim8);void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == GPIO_PIN_13) {
bmsState = (bmsState == ACTIVE) ? INACTIVE : ACTIVE;
}
}β‘ Make sure EXTI15_10_IRQn is enabled in stm32f4xx_it.c.
EEPROM driver initialization example:
EE24_HandleTypeDef ee24;
EE24_Init(&ee24, &hi2c1, 0xA0);Supports both bare-metal and RTOS modes, with built-in lock and delay handling.
The firmware streams data to Node-RED over USART1 (DMA) at 230400 baud.
Data is sent as JSON-formatted strings and can be parsed directly in Node-RED dashboards.
Example payload:
{
"dieTemp": 24.5,
"SegVoltage": 37.47,
"rth_temps": { "ic": 1, "temps": [23.4, 24.1, 25.0] }
}The included flows.json file provides a prebuilt Node-RED dashboard with:
- Real-time gauges for temperatures and voltages
- Per-cell voltage tables
- Line charts for temperature sensors
- Fault and CAN status indicators
- Debug console for raw UART logs
π To use: Import flows.json into Node-RED via Import > Clipboard.
If you see:
WARNING! PEC ERROR - IC: 1, IC1: 0xF3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, CC: 61
β Check SPI polarity (CPOL=1) and phase (CPHA=1)
β Verify manual CS timing between transactions
β Validate CRC10/CRC15 calculation in bms_utility.c
β Ensure correct wake-up delay (use bms_delayUs())
- Enable float support for
printf: add-u _printf_floatto linker flags. - Ensure SPI runs near 2 Mbps by adjusting APB2 clock and SPI prescaler.
- SPI communication with ADBMS6822 verified
- PEC (CRC10/CRC15) verified
- CAN communication functional
- EEPROM read/write functional
- UART communication with Node-RED operational
- Timers and EXTI working
This project is intended for internal development and testing of BMS communication firmware using STM32F4 microcontrollers.