Skip to content

CAN Communication

The can_comm.c module handles packaging the acquired battery metrics into CAN frames and managing their transmission over the vehicle's CAN bus.

Data Aggregation

The module is responsible for calculating aggregated statistics that are beneficial for vehicle diagnostics:

  • Rolling Average: Maintains a 50-sample (10-second) rolling history of instantaneous current values.
  • Peak Current: Tracks the maximum absolute current seen within the rolling 10-second window.

CAN Messages

The LVSOC-26 board transmits its payload over two separate CAN frames, sequentially linked from its base CAN ID (LVSOC_CAN_BASE_ID).

Message 1

Transmits primary electrical and charge state data:

  • Bytes 0-1: Voltage (in mV)
  • Bytes 2-3: Instantaneous Current (in 10mA increments)
  • Bytes 4-5: State of Charge (SOC, scaled by 10)
  • Bytes 6-7: 10-second Peak Current (in 10mA increments)

Message 2

Transmits capacity and long-term diagnostic data:

  • Bytes 0-1: Remaining Capacity (in mAh)
  • Bytes 2-3: Reserved
  • Bytes 4-5: Relevant Time (TTE or TTF, in minutes)
  • Bytes 6-7: 10-second Average Current (in 10mA increments)

Hardware Integration

The driver wraps the STM32 bxCAN driver via our generic_can_driver.c interface. It sets up an RX filter (accepting all messages) to handle incoming diagnostic requests or configurations, and uses a ring buffer abstraction (CAN_send_single_frame) to safely queue the two transmission frames without blocking the main execution loop.

Released under the MIT License.