Skip to content

About

command line tool to decipher max17320 BMS for Raspberry pi.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

MAX17320 Dev Tools

Building

make build

Usage

dump all registers to json sudo ./max17320_read

query specific registers by address or name (case insensitive) e.g. sudo ./max17320_read Status VCell 0x05

Pipe register list into app

cat /path/to/register/list | xarg sudo ./max17320_read

CSV output

add --csv to poll the selected registers continuously, emitting a header row of register names followed by one row of values per reading. output is flushed per row so it can be tailed or appended to a log file sudo ./max17320_read --csv Current Power >> log.csv

units are named once in the header rather than repeated on every value

Current (mA),Power (mW)
-125.000000,-924.800000

polling runs at 1 Hz until interrupted with ctrl-c. use --interval to set a different period in seconds (fractions allowed) sudo ./max17320_read --csv --interval 0.5 Current Power

the flags can appear anywhere in the argument list, and work with a piped register list too cat /path/to/register/list | xargs sudo ./max17320_read --csv

Clearing recorded current peaks

--clear-max-current resets the MaxMinCurr register to its power-on value before the first reading, so a run reports only the current seen while it was running sudo ./max17320_read --clear-max-current --csv Current MaxMinCurr

this clears the gauge's write protection and leaves it cleared, matching what the rest of the driver does — re-locking would write 0x00F9 to CommStat and re-enable both FETs

Nonvolatile memory

the expected nonvolatile settings are the g_nv_expected table in src/bms_ctl.c, kept in step with whale-tag-stm32/src/battery/bms_ctl.c. select the board revision and cells with BMS_VERSION and BMS_CELLS

compare the pack's nonvolatile settings against the table, exiting nonzero on any mismatch sudo ./max17320_read --verify-nv

program the table into nonvolatile memory sudo ./max17320_read --program-nv

the MAX17320 only allows a limited number of nonvolatile updates, so programming

  • is skipped when the pack already holds the expected values
  • is refused when fewer than 3 updates remain
  • writes shadow RAM and reads it back before committing anything
  • takes about 8 s for the block copy, then resets the gauge and verifies the stored values
  • re-enables write protection afterwards, as the STM32 firmware does

Shutdown

open both the charge and discharge FETs, cutting current through the pack sudo ./max17320_read --shutdown

both FETs are opened in a single CommStat write, so a host powered through the pack loses power right after the write and never prints the confirmation. on a host powered separately, CommStat is read back to confirm both FETs are open.

this only takes effect when comm override is enabled in nProtCfg (CmOvrdEn). with nothing attached, the open pack side floats and a meter can still read a few volts on it; it drops to 0 V under load

write protection is cleared and left cleared. note that clearing or re-locking write protection rewrites CommStat and closes both FETs again, so any later command that does so (e.g. --clear-max-current, --program-nv) reconnects the pack

Charge and discharge FETs

enable or disable each FET on its own. a FET that is not named is left as it is, and the flags combine into a single CommStat write sudo ./max17320_read --disable-charge sudo ./max17320_read --enable-charge --disable-discharge

CommStat is read back and the state of both FETs printed. these flags set or clear the comm override only: an enabled FET is still opened by the protector on a fault, so check ProtStatus if one stays off. write protection is cleared in the same writes that set the FETs, so neither FET briefly closes along the way, and is left cleared as with --shutdown

Clearing faults

clear the latched alerts in ProtAlrt and Status, printing the fault registers before and after sudo ./max17320_read --clear-faults

combine it with the FET flags to clear the faults and then re-enable the FETs in one go sudo ./max17320_read --clear-faults --enable-charge --enable-discharge

  • every ProtAlrt bit is cleared, along with the Status alert bits (PA, Imn/Imx, Vmn/Vmx, Tmn/Tmx, Smn/Smx, dSOCi). Status.POR is left set so a reset stays visible
  • write protection is cleared without changing either FET override, and left cleared
  • ProtStatus follows the live fault state and cannot be cleared by writing. a fault there (e.g. UVP, TooColdC, Full) holds its FET open until the condition recovers, whatever the FET flags request. the command exits nonzero while any remain, but the FET overrides are still applied so they take effect once the fault clears
  • an alert whose condition still holds (e.g. Vmn below the voltage alert threshold) is set again on the gauge's next reading

About

command line tool to decipher max17320 BMS for Raspberry pi.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages