Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC681x.h File Reference

General BMS Library. More...

Detailed Description

General BMS Library.

Library for LTC681x Multi-cell Battery Monitor.

Author
BMS (bms.s.nosp@m.uppo.nosp@m.rt@an.nosp@m.alog.nosp@m..com)

Copyright 2019(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  • The use of this software may or may not infringe the patent rights of one or more patent holders. This license does not release you from the requirement that you obtain separate licenses from these patent holders to use this software.
  • Use of the software either in source or binary form, must be run on or directly connected to an Analog Devices Inc. component.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file LTC681x.h.

Go to the source code of this file.

Data Structures

struct  cv
 Cell Voltage data structure. More...
 
struct  ax
 AUX Reg Voltage Data structure. More...
 
struct  st
 Status Reg data structure. More...
 
struct  ic_register
 IC register structure. More...
 
struct  pec_counter
 PEC error counter structure. More...
 
struct  register_cfg
 Register configuration structure. More...
 
struct  cell_asic
 Cell variable structure. More...
 

Functions

void wakeup_idle (uint8_t total_ic)
 Wake isoSPI up from IDlE state and enters the READY state. More...
 
void wakeup_sleep (uint8_t total_ic)
 Wake the LTC681x from the sleep state. More...
 
void cmd_68 (uint8_t tx_cmd[2])
 Sends a command to the BMS IC. More...
 
void write_68 (uint8_t total_ic, uint8_t tx_cmd[2], uint8_t data[])
 Writes an array of data to the daisy chain. More...
 
int8_t read_68 (uint8_t total_ic, uint8_t tx_cmd[2], uint8_t *rx_data)
 Issues a command onto the daisy chain and reads back 6*total_ic data in the rx_data array. More...
 
uint16_t pec15_calc (uint8_t len, uint8_t *data)
 Calculates and returns the CRC15. More...
 
void LTC681x_wrcfg (uint8_t total_ic, cell_asic *ic)
 Write the LTC681x CFGRA register This command will write the configuration registers of the LTC681xs connected in a daisy chain stack. More...
 
void LTC681x_wrcfgb (uint8_t total_ic, cell_asic *ic)
 Write the LTC681x CFGRB register This command will write the configuration registers of the LTC681xs connected in a daisy chain stack. More...
 
int8_t LTC681x_rdcfg (uint8_t total_ic, cell_asic *ic)
 Reads the LTC681x CFGRA register. More...
 
int8_t LTC681x_rdcfgb (uint8_t total_ic, cell_asic *ic)
 Reads the LTC681x CFGRB register. More...
 
void LTC681x_adcv (uint8_t MD, uint8_t DCP, uint8_t CH)
 Starts cell voltage conversion Starts ADC conversions of the LTC681x Cpin inputs. More...
 
void LTC681x_adax (uint8_t MD, uint8_t CHG)
 Start a GPIO and Vref2 Conversion. More...
 
void LTC681x_adstat (uint8_t MD, uint8_t CHST)
 Start a Status ADC Conversion. More...
 
void LTC681x_adcvax (uint8_t MD, uint8_t DCP)
 Starts cell voltage and GPIO 1&2 conversion. More...
 
void LTC681x_adcvsc (uint8_t MD, uint8_t DCP)
 Starts cell voltage and SOC conversion. More...
 
uint8_t LTC681x_rdcv (uint8_t reg, uint8_t total_ic, cell_asic *ic)
 Reads and parses the LTC681x cell voltage registers. More...
 
int8_t LTC681x_rdaux (uint8_t reg, uint8_t total_ic, cell_asic *ic)
 Reads and parses the LTC681x auxiliary registers. More...
 
int8_t LTC681x_rdstat (uint8_t reg, uint8_t total_ic, cell_asic *ic)
 Reads and parses the LTC681x stat registers. More...
 
void LTC681x_rdcv_reg (uint8_t reg, uint8_t total_ic, uint8_t *data)
 Reads the raw cell voltage register data. More...
 
void LTC681x_rdaux_reg (uint8_t reg, uint8_t total_ic, uint8_t *data)
 Read the raw data from the LTC681x auxiliary register The function reads a single GPIO voltage register and stores the read data in the *data point as a byte array. More...
 
void LTC681x_rdstat_reg (uint8_t reg, uint8_t total_ic, uint8_t *data)
 Read the raw data from the LTC681x stat register The function reads a single Status register and stores the read data in the *data point as a byte array. More...
 
int8_t parse_cells (uint8_t current_ic, uint8_t cell_reg, uint8_t cell_data[], uint16_t *cell_codes, uint8_t *ic_pec)
 Helper function that parses voltage measurement registers. More...
 
uint8_t LTC681x_pladc ()
 Sends the poll ADC command. More...
 
uint32_t LTC681x_pollAdc ()
 This function will block operation until the ADC has finished it's conversion. More...
 
void LTC681x_clrcell ()
 Clears the LTC681x Cell voltage registers The command clears the cell voltage registers and initializes all values to 1. More...
 
void LTC681x_clraux ()
 Clears the LTC681x Auxiliary registers The command clears the Auxiliary registers and initializes all values to 1. More...
 
void LTC681x_clrstat ()
 Clears the LTC681x Stat registers The command clears the Stat registers and initializes all values to 1. More...
 
void LTC681x_diagn ()
 Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnostic Self Test This test takes roughly 1ms to complete. More...
 
void LTC681x_cvst (uint8_t MD, uint8_t ST)
 Starts cell voltage self test conversion. More...
 
void LTC681x_axst (uint8_t MD, uint8_t ST)
 Start an Auxiliary Register Self Test Conversion. More...
 
void LTC681x_statst (uint8_t MD, uint8_t ST)
 Start a Status Register Self Test Conversion. More...
 
void LTC681x_adol (uint8_t MD, uint8_t DCP)
 Starts cell voltage overlap conversion. More...
 
void LTC681x_adaxd (uint8_t MD, uint8_t CHG)
 Start an GPIO Redundancy test. More...
 
void LTC681x_adstatd (uint8_t MD, uint8_t CHST)
 Start a Status register redundancy test Conversion. More...
 
int16_t LTC681x_run_cell_adc_st (uint8_t adc_reg, uint8_t total_ic, cell_asic *ic, uint8_t md, bool adcopt)
 Helper function that runs the ADC Self Tests. More...
 
uint16_t LTC681x_st_lookup (uint8_t MD, uint8_t ST, bool adcopt)
 Self Test Helper Function. More...
 
uint16_t LTC681x_run_adc_overlap (uint8_t total_ic, cell_asic *ic)
 Helper Function that runs the ADC Overlap test. More...
 
int16_t LTC681x_run_adc_redundancy_st (uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic *ic)
 Helper function that runs the ADC Digital Redundancy commands and checks output for errors. More...
 
void LTC681x_adow (uint8_t MD, uint8_t PUP, uint8_t CH, uint8_t DCP)
 Start an open wire Conversion. More...
 
void LTC681x_axow (uint8_t MD, uint8_t PUP)
 Start GPIOs open wire ADC conversion. More...
 
void LTC681x_run_openwire_single (uint8_t total_ic, cell_asic *ic)
 Helper function that runs the data sheet algorithm for open wire for single cell detection. More...
 
void LTC681x_run_openwire_multi (uint8_t total_ic, cell_asic *ic)
 Helper function that runs open wire for multiple cell and two consecutive cells detection. More...
 
void LTC681x_run_gpio_openwire (uint8_t total_ic, cell_asic *ic)
 Runs open wire for GPIOs. More...
 
void LTC681x_clear_discharge (uint8_t total_ic, cell_asic *ic)
 Helper Function to clear DCC bits in the CFGR Registers. More...
 
void LTC681x_wrpwm (uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
 Write the LTC681x PWM register This command will write the pwm registers of the LTC681x connected in a daisy chain stack. More...
 
int8_t LTC681x_rdpwm (uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
 Reads pwm registers of a LTC681x daisy chain. More...
 
void LTC681x_wrsctrl (uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
 Write the LTC681x Sctrl register. More...
 
int8_t LTC681x_rdsctrl (uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
 Reads sctrl registers of a LTC681x daisy chain. More...
 
void LTC681x_stsctrl ()
 Start Sctrl data communication This command will start the sctrl pulse communication over the spins. More...
 
void LTC681x_clrsctrl ()
 Clears the LTC681x SCTRL registers The command clears the SCTRL registers and initializes all values to 0. More...
 
void LTC681x_wrcomm (uint8_t total_ic, cell_asic *ic)
 Write the LTC681x COMM register This command will write the comm registers of the LTC681x connected in a daisy chain stack. More...
 
int8_t LTC681x_rdcomm (uint8_t total_ic, cell_asic *ic)
 Reads comm registers of a LTC681x daisy chain. More...
 
void LTC681x_stcomm (uint8_t len)
 Issues a stcomm command and clocks data out of the COMM register. More...
 
void LTC681x_check_pec (uint8_t total_ic, uint8_t reg, cell_asic *ic)
 Helper Function that counts overall PEC errors and register/IC PEC errors. More...
 
void LTC681x_reset_crc_count (uint8_t total_ic, cell_asic *ic)
 Helper Function that resets the PEC error counters. More...
 
void LTC681x_init_cfg (uint8_t total_ic, cell_asic *ic)
 Helper Function to initialize the CFGR data structures. More...
 
void LTC681x_set_cfgr (uint8_t nIC, cell_asic *ic, bool refon, bool adcopt, bool gpio[5], bool dcc[12], bool dcto[4], uint16_t uv, uint16_t ov)
 Helper function to set appropriate bits in CFGR register based on bit function. More...
 
void LTC681x_set_cfgr_refon (uint8_t nIC, cell_asic *ic, bool refon)
 Helper function to turn the REFON bit HIGH or LOW. More...
 
void LTC681x_set_cfgr_adcopt (uint8_t nIC, cell_asic *ic, bool adcopt)
 Helper function to turn the ADCOPT bit HIGH or LOW. More...
 
void LTC681x_set_cfgr_gpio (uint8_t nIC, cell_asic *ic, bool gpio[])
 Helper function to turn the GPIO bits HIGH or LOW. More...
 
void LTC681x_set_cfgr_dis (uint8_t nIC, cell_asic *ic, bool dcc[])
 Helper function to turn the DCC bits HIGH or LOW. More...
 
void LTC681x_set_cfgr_dcto (uint8_t nIC, cell_asic *ic, bool dcto[])
 Helper function to control discharge time value. More...
 
void LTC681x_set_cfgr_uv (uint8_t nIC, cell_asic *ic, uint16_t uv)
 Helper function to set uv field in CFGRA register. More...
 
void LTC681x_set_cfgr_ov (uint8_t nIC, cell_asic *ic, uint16_t ov)
 Helper function to set ov field in CFGRA register. More...
 

Macros

#define LINDUINO
 
#define IC_LTC6813
 
#define MD_422HZ_1KHZ   0
 
#define MD_27KHZ_14KHZ   1
 
#define MD_7KHZ_3KHZ   2
 
#define MD_26HZ_2KHZ   3
 
#define ADC_OPT_ENABLED   1
 
#define ADC_OPT_DISABLED   0
 
#define CELL_CH_ALL   0
 
#define CELL_CH_1and7   1
 
#define CELL_CH_2and8   2
 
#define CELL_CH_3and9   3
 
#define CELL_CH_4and10   4
 
#define CELL_CH_5and11   5
 
#define CELL_CH_6and12   6
 
#define SELFTEST_1   1
 
#define SELFTEST_2   2
 
#define AUX_CH_ALL   0
 
#define AUX_CH_GPIO1   1
 
#define AUX_CH_GPIO2   2
 
#define AUX_CH_GPIO3   3
 
#define AUX_CH_GPIO4   4
 
#define AUX_CH_GPIO5   5
 
#define AUX_CH_VREF2   6
 
#define STAT_CH_ALL   0
 
#define STAT_CH_SOC   1
 
#define STAT_CH_ITEMP   2
 
#define STAT_CH_VREGA   3
 
#define STAT_CH_VREGD   4
 
#define REG_ALL   0
 
#define REG_1   1
 
#define REG_2   2
 
#define REG_3   3
 
#define REG_4   4
 
#define REG_5   5
 
#define REG_6   6
 
#define DCP_DISABLED   0
 
#define DCP_ENABLED   1
 
#define PULL_UP_CURRENT   1
 
#define PULL_DOWN_CURRENT   0
 
#define NUM_RX_BYT   8
 
#define CELL   1
 
#define AUX   2
 
#define STAT   3
 
#define CFGR   0
 
#define CFGRB   4
 
#define CS_PIN   10
 

Variables

const uint16_t crc15Table [256] PROGMEM
 

Function Documentation

◆ cmd_68()

void cmd_68 ( uint8_t  tx_cmd[2])

Sends a command to the BMS IC.

This code will calculate the PEC code for the transmitted command

Returns
void 2 byte array containing the BMS command to be sent

Definition at line 77 of file LTC681x.cpp.

◆ LTC681x_adax()

void LTC681x_adax ( uint8_t  MD,
uint8_t  CHG 
)

Start a GPIO and Vref2 Conversion.

Returns
void
Parameters
MDADC Conversion Mode
CHGSets which GPIO channels are converted

Definition at line 367 of file LTC681x.cpp.

◆ LTC681x_adaxd()

void LTC681x_adaxd ( uint8_t  MD,
uint8_t  CHG 
)

Start an GPIO Redundancy test.

Returns
void
Parameters
MDADC Conversion Mode
CHGSets which GPIO channels are converted

Definition at line 1038 of file LTC681x.cpp.

◆ LTC681x_adcv()

void LTC681x_adcv ( uint8_t  MD,
uint8_t  DCP,
uint8_t  CH 
)

Starts cell voltage conversion Starts ADC conversions of the LTC681x Cpin inputs.

The type of ADC conversion executed can be changed by setting the following parameters:

Returns
void
Parameters
MDADC conversion Mode
DCPControls if Discharge is permitted during conversion
CHSets which Cell channels are converted

Definition at line 350 of file LTC681x.cpp.

◆ LTC681x_adcvax()

void LTC681x_adcvax ( uint8_t  MD,
uint8_t  DCP 
)

Starts cell voltage and GPIO 1&2 conversion.

Returns
void
Parameters
MDADC Conversion Mode
DCPControls if Discharge is permitted during conversion

Definition at line 415 of file LTC681x.cpp.

◆ LTC681x_adcvsc()

void LTC681x_adcvsc ( uint8_t  MD,
uint8_t  DCP 
)

Starts cell voltage and SOC conversion.

Returns
void
Parameters
MDADC Conversion Mode
DCPControls if Discharge is permitted during conversion

Definition at line 399 of file LTC681x.cpp.

◆ LTC681x_adol()

void LTC681x_adol ( uint8_t  MD,
uint8_t  DCP 
)

Starts cell voltage overlap conversion.

Returns
void
Parameters
MDADC Conversion Mode
DCPDischarge permitted during conversion

Definition at line 1022 of file LTC681x.cpp.

◆ LTC681x_adow()

void LTC681x_adow ( uint8_t  MD,
uint8_t  PUP,
uint8_t  CH,
uint8_t  DCP 
)

Start an open wire Conversion.

Returns
void
Parameters
MDADC Conversion Mode
PUPPull up/Pull down current
CHChannels
DCPDischarge Permit

Definition at line 1292 of file LTC681x.cpp.

◆ LTC681x_adstat()

void LTC681x_adstat ( uint8_t  MD,
uint8_t  CHST 
)

Start a Status ADC Conversion.

Returns
void
Parameters
MDADC Conversion Mode
CHSTSets which Stat channels are converted

Definition at line 383 of file LTC681x.cpp.

◆ LTC681x_adstatd()

void LTC681x_adstatd ( uint8_t  MD,
uint8_t  CHST 
)

Start a Status register redundancy test Conversion.

Returns
void
Parameters
MDADC Mode
CHSTSets which Status channels are converted

Definition at line 1054 of file LTC681x.cpp.

◆ LTC681x_axow()

void LTC681x_axow ( uint8_t  MD,
uint8_t  PUP 
)

Start GPIOs open wire ADC conversion.

Returns
void
Parameters
MDADC Mode
PUPPull up/Pull down current

Definition at line 1310 of file LTC681x.cpp.

◆ LTC681x_axst()

void LTC681x_axst ( uint8_t  MD,
uint8_t  ST 
)

Start an Auxiliary Register Self Test Conversion.

Returns
void
Parameters
MDADC Conversion Mode
STSets if self test 1 or 2 is run

Definition at line 990 of file LTC681x.cpp.

◆ LTC681x_check_pec()

void LTC681x_check_pec ( uint8_t  total_ic,
uint8_t  reg,
cell_asic ic 
)

Helper Function that counts overall PEC errors and register/IC PEC errors.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
regType of register
icA two dimensional array that will store the data

Definition at line 1999 of file LTC681x.cpp.

◆ LTC681x_clear_discharge()

void LTC681x_clear_discharge ( uint8_t  total_ic,
cell_asic ic 
)

Helper Function to clear DCC bits in the CFGR Registers.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

Definition at line 1682 of file LTC681x.cpp.

◆ LTC681x_clraux()

void LTC681x_clraux ( )

Clears the LTC681x Auxiliary registers The command clears the Auxiliary registers and initializes all values to 1.

The register will read back hexadecimal 0xFF after the command is sent.

Returns
void

Definition at line 948 of file LTC681x.cpp.

◆ LTC681x_clrcell()

void LTC681x_clrcell ( )

Clears the LTC681x Cell voltage registers The command clears the cell voltage registers and initializes all values to 1.

The register will read back hexadecimal 0xFF after the command is sent.

Returns
void

Definition at line 937 of file LTC681x.cpp.

◆ LTC681x_clrsctrl()

void LTC681x_clrsctrl ( )

Clears the LTC681x SCTRL registers The command clears the SCTRL registers and initializes all values to 0.

The register will read back hexadecimal 0x00 after the command is sent.

Returns
void

Definition at line 1900 of file LTC681x.cpp.

◆ LTC681x_clrstat()

void LTC681x_clrstat ( )

Clears the LTC681x Stat registers The command clears the Stat registers and initializes all values to 1.

The register will read back hexadecimal 0xFF after the command is sent.

Returns
void

Definition at line 960 of file LTC681x.cpp.

◆ LTC681x_cvst()

void LTC681x_cvst ( uint8_t  MD,
uint8_t  ST 
)

Starts cell voltage self test conversion.

Returns
void
Parameters
MDADC Conversion Mode
STSets if self test 1 or 2 is run

Definition at line 974 of file LTC681x.cpp.

◆ LTC681x_diagn()

void LTC681x_diagn ( )

Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnostic Self Test This test takes roughly 1ms to complete.

The MUXFAIL bit will be updated, the bit will be set to 1 for a failure and 0 if the test has been passed.

Returns
void

Definition at line 967 of file LTC681x.cpp.

◆ LTC681x_init_cfg()

void LTC681x_init_cfg ( uint8_t  total_ic,
cell_asic ic 
)

Helper Function to initialize the CFGR data structures.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

Definition at line 2084 of file LTC681x.cpp.

◆ LTC681x_pladc()

uint8_t LTC681x_pladc ( )

Sends the poll ADC command.

Returns
uint8_t adc_state 1 byte read back after a pladc command. If the byte is not 0xFF ADC conversion has completed

Definition at line 878 of file LTC681x.cpp.

◆ LTC681x_pollAdc()

uint32_t LTC681x_pollAdc ( )

This function will block operation until the ADC has finished it's conversion.

Returns
uint32_t counter The approximate time it took for the ADC function to complete.

Definition at line 899 of file LTC681x.cpp.

◆ LTC681x_rdaux()

int8_t LTC681x_rdaux ( uint8_t  reg,
uint8_t  total_ic,
cell_asic ic 
)

Reads and parses the LTC681x auxiliary registers.

The function is used to read the parsed GPIO codes of the LTC681x. This function will send the requested read commands parse the data and store the gpio voltages in the cell_asic structure.

Returns
int8_t, PEC Status 0: No PEC error detected -1: PEC error detected, retry read
Parameters
regDetermines which GPIO voltage register is read back.
total_icthe number of ICs in the system
icArray of the parsed aux codes

Definition at line 498 of file LTC681x.cpp.

◆ LTC681x_rdaux_reg()

void LTC681x_rdaux_reg ( uint8_t  reg,
uint8_t  total_ic,
uint8_t *  data 
)

Read the raw data from the LTC681x auxiliary register The function reads a single GPIO voltage register and stores the read data in the *data point as a byte array.

This function is rarely used outside of the LTC681x_rdaux() command.

Returns
void
Parameters
regDetermines which GPIO voltage register is read back
total_icThe number of ICs in the system
dataArray of the unparsed auxiliary codes

Definition at line 748 of file LTC681x.cpp.

◆ LTC681x_rdcfg()

int8_t LTC681x_rdcfg ( uint8_t  total_ic,
cell_asic ic 
)

Reads the LTC681x CFGRA register.

Returns
int8_t, PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC
Parameters
total_icNumber of ICs in the system
icA two dimensional array that the function stores the read configuration data.

◆ LTC681x_rdcfgb()

int8_t LTC681x_rdcfgb ( uint8_t  total_ic,
cell_asic ic 
)

Reads the LTC681x CFGRB register.

Returns
int8_t, PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC
Parameters
total_icNumber of ICs in the system
icA two dimensional array that the function stores the read configuration data.

◆ LTC681x_rdcomm()

int8_t LTC681x_rdcomm ( uint8_t  total_ic,
cell_asic ic 
)

Reads comm registers of a LTC681x daisy chain.

Returns
int8_t, pec_error PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC
Parameters
total_icNumber of ICs in the system
icA two dimensional array that the function stores the read data

◆ LTC681x_rdcv()

uint8_t LTC681x_rdcv ( uint8_t  reg,
uint8_t  total_ic,
cell_asic ic 
)

Reads and parses the LTC681x cell voltage registers.

The function is used to read the cell codes of the LTC681x. This function will send the requested read commands parse the data and store the cell voltages in the cell_asic structure.

Returns
uint8_t, PEC Status. 0: No PEC error detected -1: PEC error detected, retry read
Parameters
regControls which cell voltage register is read back.
total_icThe number of ICs in the system
icArray of the parsed cell codes

Definition at line 436 of file LTC681x.cpp.

◆ LTC681x_rdcv_reg()

void LTC681x_rdcv_reg ( uint8_t  reg,
uint8_t  total_ic,
uint8_t *  data 
)

Reads the raw cell voltage register data.

Returns
void
Parameters
regDetermines which cell voltage register is read back
total_icThe number of ICs in the
dataAn array of the unparsed cell codes

Definition at line 694 of file LTC681x.cpp.

◆ LTC681x_rdpwm()

int8_t LTC681x_rdpwm ( uint8_t  total_ic,
uint8_t  pwmReg,
cell_asic ic 
)

Reads pwm registers of a LTC681x daisy chain.

Returns
int8_t, pec_error PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC
Parameters
total_icNumber of ICs in the system
pwmRegThe PWM Register to be written A or B
icA two dimensional array that will store the read data

◆ LTC681x_rdsctrl()

int8_t LTC681x_rdsctrl ( uint8_t  total_ic,
uint8_t  sctrl_reg,
cell_asic ic 
)

Reads sctrl registers of a LTC681x daisy chain.

Returns
int8_t, pec_error PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC
Parameters
total_icNumber of ICs in the daisy chain
sctrl_regThe Sctrl Register to be written A or B
icA two dimensional array that the function stores the read data

Definition at line 1827 of file LTC681x.cpp.

◆ LTC681x_rdstat()

int8_t LTC681x_rdstat ( uint8_t  reg,
uint8_t  total_ic,
cell_asic ic 
)

Reads and parses the LTC681x stat registers.

The function is used to read the parsed status codes of the LTC681x. This function will send the requested read commands parse the data and store the status voltages in the cell_asic structure

Returns
int8_t, PEC Status 0: No PEC error detected -1: PEC error detected, retry read
Parameters
regDetermines which Stat register is read back.
total_icThe number of ICs in the system
icArray of the parsed stat codes

Definition at line 560 of file LTC681x.cpp.

◆ LTC681x_rdstat_reg()

void LTC681x_rdstat_reg ( uint8_t  reg,
uint8_t  total_ic,
uint8_t *  data 
)

Read the raw data from the LTC681x stat register The function reads a single Status register and stores the read data in the *data point as a byte array.

This function is rarely used outside of the LTC681x_rdstat() command.

Returns
void
Parameters
regDetermines which stat register is read back
total_icThe number of ICs in the system
dataArray of the unparsed stat codes

Definition at line 797 of file LTC681x.cpp.

◆ LTC681x_reset_crc_count()

void LTC681x_reset_crc_count ( uint8_t  total_ic,
cell_asic ic 
)

Helper Function that resets the PEC error counters.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

Definition at line 2059 of file LTC681x.cpp.

◆ LTC681x_run_adc_overlap()

uint16_t LTC681x_run_adc_overlap ( uint8_t  total_ic,
cell_asic ic 
)

Helper Function that runs the ADC Overlap test.

Returns
uint16_t, error 0: Pass -1: False, Error detected
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

Definition at line 1158 of file LTC681x.cpp.

◆ LTC681x_run_adc_redundancy_st()

int16_t LTC681x_run_adc_redundancy_st ( uint8_t  adc_mode,
uint8_t  adc_reg,
uint8_t  total_ic,
cell_asic ic 
)

Helper function that runs the ADC Digital Redundancy commands and checks output for errors.

Returns
int16_t, error Number of errors detected.
Parameters
adc_modeADC Mode
adc_regType of register
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

Definition at line 1188 of file LTC681x.cpp.

◆ LTC681x_run_cell_adc_st()

int16_t LTC681x_run_cell_adc_st ( uint8_t  adc_reg,
uint8_t  total_ic,
cell_asic ic,
uint8_t  md,
bool  adcopt 
)

Helper function that runs the ADC Self Tests.

Returns
int16_t, error Number of errors detected.
Parameters
adc_regType of register
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data
mdADC Mode
adcoptADCOPT bit in the configuration register

Definition at line 1070 of file LTC681x.cpp.

◆ LTC681x_run_gpio_openwire()

void LTC681x_run_gpio_openwire ( uint8_t  total_ic,
cell_asic ic 
)

Runs open wire for GPIOs.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

◆ LTC681x_run_openwire_multi()

void LTC681x_run_openwire_multi ( uint8_t  total_ic,
cell_asic ic 
)

Helper function that runs open wire for multiple cell and two consecutive cells detection.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

◆ LTC681x_run_openwire_single()

void LTC681x_run_openwire_single ( uint8_t  total_ic,
cell_asic ic 
)

Helper function that runs the data sheet algorithm for open wire for single cell detection.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
icA two dimensional array that will store the data

◆ LTC681x_set_cfgr()

void LTC681x_set_cfgr ( uint8_t  nIC,
cell_asic ic,
bool  refon,
bool  adcopt,
bool  gpio[5],
bool  dcc[12],
bool  dcto[4],
uint16_t  uv,
uint16_t  ov 
)

Helper function to set appropriate bits in CFGR register based on bit function.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
refonThe REFON bit
adcoptThe ADCOPT bit
gpioThe GPIO bits
dccThe DCC bits
dctoThe Dcto bits
uvThe UV value
ovThe OV value

Definition at line 2098 of file LTC681x.cpp.

◆ LTC681x_set_cfgr_adcopt()

void LTC681x_set_cfgr_adcopt ( uint8_t  nIC,
cell_asic ic,
bool  adcopt 
)

Helper function to turn the ADCOPT bit HIGH or LOW.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
adcoptThe ADCOPT bit

Definition at line 2126 of file LTC681x.cpp.

◆ LTC681x_set_cfgr_dcto()

void LTC681x_set_cfgr_dcto ( uint8_t  nIC,
cell_asic ic,
bool  dcto[] 
)

Helper function to control discharge time value.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
dctoThe Dcto bits

◆ LTC681x_set_cfgr_dis()

void LTC681x_set_cfgr_dis ( uint8_t  nIC,
cell_asic ic,
bool  dcc[] 
)

Helper function to turn the DCC bits HIGH or LOW.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
dccThe DCC bits

◆ LTC681x_set_cfgr_gpio()

void LTC681x_set_cfgr_gpio ( uint8_t  nIC,
cell_asic ic,
bool  gpio[] 
)

Helper function to turn the GPIO bits HIGH or LOW.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
gpioThe GPIO bits

◆ LTC681x_set_cfgr_ov()

void LTC681x_set_cfgr_ov ( uint8_t  nIC,
cell_asic ic,
uint16_t  ov 
)

Helper function to set ov field in CFGRA register.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
ovThe OV value

Definition at line 2177 of file LTC681x.cpp.

◆ LTC681x_set_cfgr_refon()

void LTC681x_set_cfgr_refon ( uint8_t  nIC,
cell_asic ic,
bool  refon 
)

Helper function to turn the REFON bit HIGH or LOW.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
refonThe REFON bit

Definition at line 2119 of file LTC681x.cpp.

◆ LTC681x_set_cfgr_uv()

void LTC681x_set_cfgr_uv ( uint8_t  nIC,
cell_asic ic,
uint16_t  uv 
)

Helper function to set uv field in CFGRA register.

Returns
void
Parameters
nICCurrent IC
icA two dimensional array that will store the data
uvThe UV value

Definition at line 2168 of file LTC681x.cpp.

◆ LTC681x_st_lookup()

uint16_t LTC681x_st_lookup ( uint8_t  MD,
uint8_t  ST,
bool  adcopt 
)

Self Test Helper Function.

Returns
uint16_t test_pattern returns the register data pattern for a given ADC MD and Self test
Parameters
MDADC Mode
STSelf Test
adcoptADCOPT bit in the configuration register

Definition at line 1245 of file LTC681x.cpp.

◆ LTC681x_statst()

void LTC681x_statst ( uint8_t  MD,
uint8_t  ST 
)

Start a Status Register Self Test Conversion.

Returns
void
Parameters
MDADC Conversion Mode
STSets if self test 1 or 2 is run

Definition at line 1006 of file LTC681x.cpp.

◆ LTC681x_stcomm()

void LTC681x_stcomm ( uint8_t  len)

Issues a stcomm command and clocks data out of the COMM register.

Returns
void
Parameters
lenLength of data to be transmitted

Definition at line 1978 of file LTC681x.cpp.

◆ LTC681x_stsctrl()

void LTC681x_stsctrl ( )

Start Sctrl data communication This command will start the sctrl pulse communication over the spins.

Returns
void

Definition at line 1879 of file LTC681x.cpp.

◆ LTC681x_wrcfg()

void LTC681x_wrcfg ( uint8_t  total_ic,
cell_asic ic 
)

Write the LTC681x CFGRA register This command will write the configuration registers of the LTC681xs connected in a daisy chain stack.

The configuration is written in descending order so the last device's configuration is written first.

Returns
void
Parameters
total_icThe number of ICs being written to
icA two dimensional array of the configuration data that will be written

◆ LTC681x_wrcfgb()

void LTC681x_wrcfgb ( uint8_t  total_ic,
cell_asic ic 
)

Write the LTC681x CFGRB register This command will write the configuration registers of the LTC681xs connected in a daisy chain stack.

The configuration is written in descending order so the last device's configuration is written first.

Returns
void
Parameters
total_icThe number of ICs being written to
icA two dimensional array of the configuration data that will be written

◆ LTC681x_wrcomm()

void LTC681x_wrcomm ( uint8_t  total_ic,
cell_asic ic 
)

Write the LTC681x COMM register This command will write the comm registers of the LTC681x connected in a daisy chain stack.

The comm is written in descending order so the last device's configuration is written first.

Returns
void
Parameters
total_icThe number of ICs being written to
icA two dimensional array that will store the data to be written

◆ LTC681x_wrpwm()

void LTC681x_wrpwm ( uint8_t  total_ic,
uint8_t  pwmReg,
cell_asic ic 
)

Write the LTC681x PWM register This command will write the pwm registers of the LTC681x connected in a daisy chain stack.

The pwm is written in descending order so the last device's pwm is written first.

Returns
void
Parameters
total_icThe number of ICs being written to
pwmRegThe PWM Register to be written
icA two dimensional array that will store the data to be written

◆ LTC681x_wrsctrl()

void LTC681x_wrsctrl ( uint8_t  total_ic,
uint8_t  sctrl_reg,
cell_asic ic 
)

Write the LTC681x Sctrl register.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
sctrl_regThe Sctrl Register to be written A or B
icA two dimensional array that will store the data to be written

Definition at line 1791 of file LTC681x.cpp.

◆ parse_cells()

int8_t parse_cells ( uint8_t  current_ic,
uint8_t  cell_reg,
uint8_t  cell_data[],
uint16_t *  cell_codes,
uint8_t *  ic_pec 
)

Helper function that parses voltage measurement registers.

Returns
int8_t, pec_error PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC
Parameters
current_icCurrent IC
cell_regType of register
cell_dataUnparsed data
cell_codesParsed data
ic_pecPEC error

Definition at line 833 of file LTC681x.cpp.

◆ pec15_calc()

uint16_t pec15_calc ( uint8_t  len,
uint8_t *  data 
)

Calculates and returns the CRC15.

Returns
The calculated pec15 as an unsigned int

Calculates and returns the CRC15.

calaculates and returns the CRC15

Parameters
[in]uint8_tlen: the length of the data array being passed to the function
[in]uint8_tdata[] : the array of data that the PEC will be generated from
Returns
The calculated pec15 as an unsigned int

Calculates and returns the CRC15.

calaculates and returns the CRC15

Parameters
[in]uint8_tlen: the length of the data array being passed to the function
[in]uint8_tdata[] : the array of data that the PEC will be generated from
Returns
The calculated pec15 as an unsigned int16_t

Calculates and returns the CRC15.

calaculates and returns the CRC15

Parameters
[in]uint8_tlen: the length of the data array being passed to the function
[in]uint8_tdata[] : the array of data that the PEC will be generated from
Returns
The calculated pec15 as an unsigned int

calaculates and returns the CRC15

Parameters
[in]uint8_tlen: the length of the data array being passed to the function
[in]uint8_tdata[] : the array of data that the PEC will be generated from
Returns
The calculated pec15 as an unsigned int16_t
Parameters
lenThe length of the data array being passed to the function
dataThe array of data that the PEC will be generated from

Definition at line 985 of file LTC68041.cpp.

◆ read_68()

int8_t read_68 ( uint8_t  total_ic,
uint8_t  tx_cmd[2],
uint8_t *  rx_data 
)

Issues a command onto the daisy chain and reads back 6*total_ic data in the rx_data array.

Returns
int8_t, PEC Status. 0: Data read back has matching PEC -1: Data read back has incorrect PEC Array that the read back data will be stored in.
Parameters
total_icNumber of ICs in the daisy chain
tx_cmd2 byte array containing the BMS command to be sent

Definition at line 140 of file LTC681x.cpp.

◆ wakeup_idle()

void wakeup_idle ( uint8_t  total_ic)

Wake isoSPI up from IDlE state and enters the READY state.

Returns
voidNumber of ICs in the daisy chain

Definition at line 54 of file LTC681x.cpp.

◆ wakeup_sleep()

void wakeup_sleep ( uint8_t  total_ic)

Wake the LTC681x from the sleep state.

Returns
void Number of ICs in the daisy chain

Definition at line 65 of file LTC681x.cpp.

◆ write_68()

void write_68 ( uint8_t  total_ic,
uint8_t  tx_cmd[2],
uint8_t  data[] 
)

Writes an array of data to the daisy chain.

Returns
void
Parameters
total_icNumber of ICs in the daisy chain
tx_cmd2 byte array containing the BMS command to be sent
dataArray containing the data to be written to the BMS ICs

Definition at line 98 of file LTC681x.cpp.

Macro Definition Documentation

◆ ADC_OPT_DISABLED

#define ADC_OPT_DISABLED   0

Definition at line 67 of file LTC681x.h.

◆ ADC_OPT_ENABLED

#define ADC_OPT_ENABLED   1

Definition at line 66 of file LTC681x.h.

◆ AUX

#define AUX   2

Definition at line 110 of file LTC681x.h.

◆ AUX_CH_ALL

#define AUX_CH_ALL   0

Definition at line 80 of file LTC681x.h.

◆ AUX_CH_GPIO1

#define AUX_CH_GPIO1   1

Definition at line 81 of file LTC681x.h.

◆ AUX_CH_GPIO2

#define AUX_CH_GPIO2   2

Definition at line 82 of file LTC681x.h.

◆ AUX_CH_GPIO3

#define AUX_CH_GPIO3   3

Definition at line 83 of file LTC681x.h.

◆ AUX_CH_GPIO4

#define AUX_CH_GPIO4   4

Definition at line 84 of file LTC681x.h.

◆ AUX_CH_GPIO5

#define AUX_CH_GPIO5   5

Definition at line 85 of file LTC681x.h.

◆ AUX_CH_VREF2

#define AUX_CH_VREF2   6

Definition at line 86 of file LTC681x.h.

◆ CELL

#define CELL   1

Definition at line 109 of file LTC681x.h.

◆ CELL_CH_1and7

#define CELL_CH_1and7   1

Definition at line 70 of file LTC681x.h.

◆ CELL_CH_2and8

#define CELL_CH_2and8   2

Definition at line 71 of file LTC681x.h.

◆ CELL_CH_3and9

#define CELL_CH_3and9   3

Definition at line 72 of file LTC681x.h.

◆ CELL_CH_4and10

#define CELL_CH_4and10   4

Definition at line 73 of file LTC681x.h.

◆ CELL_CH_5and11

#define CELL_CH_5and11   5

Definition at line 74 of file LTC681x.h.

◆ CELL_CH_6and12

#define CELL_CH_6and12   6

Definition at line 75 of file LTC681x.h.

◆ CELL_CH_ALL

#define CELL_CH_ALL   0

Definition at line 69 of file LTC681x.h.

◆ CFGR

#define CFGR   0

Definition at line 112 of file LTC681x.h.

◆ CFGRB

#define CFGRB   4

Definition at line 113 of file LTC681x.h.

◆ CS_PIN

#define CS_PIN   10

Definition at line 114 of file LTC681x.h.

◆ DCP_DISABLED

#define DCP_DISABLED   0

Definition at line 102 of file LTC681x.h.

◆ DCP_ENABLED

#define DCP_ENABLED   1

Definition at line 103 of file LTC681x.h.

◆ IC_LTC6813

#define IC_LTC6813

Definition at line 59 of file LTC681x.h.

◆ LINDUINO

#define LINDUINO

Definition at line 49 of file LTC681x.h.

◆ MD_26HZ_2KHZ

#define MD_26HZ_2KHZ   3

Definition at line 64 of file LTC681x.h.

◆ MD_27KHZ_14KHZ

#define MD_27KHZ_14KHZ   1

Definition at line 62 of file LTC681x.h.

◆ MD_422HZ_1KHZ

#define MD_422HZ_1KHZ   0

Definition at line 61 of file LTC681x.h.

◆ MD_7KHZ_3KHZ

#define MD_7KHZ_3KHZ   2

Definition at line 63 of file LTC681x.h.

◆ NUM_RX_BYT

#define NUM_RX_BYT   8

Definition at line 108 of file LTC681x.h.

◆ PULL_DOWN_CURRENT

#define PULL_DOWN_CURRENT   0

Definition at line 106 of file LTC681x.h.

◆ PULL_UP_CURRENT

#define PULL_UP_CURRENT   1

Definition at line 105 of file LTC681x.h.

◆ REG_1

#define REG_1   1

Definition at line 95 of file LTC681x.h.

◆ REG_2

#define REG_2   2

Definition at line 96 of file LTC681x.h.

◆ REG_3

#define REG_3   3

Definition at line 97 of file LTC681x.h.

◆ REG_4

#define REG_4   4

Definition at line 98 of file LTC681x.h.

◆ REG_5

#define REG_5   5

Definition at line 99 of file LTC681x.h.

◆ REG_6

#define REG_6   6

Definition at line 100 of file LTC681x.h.

◆ REG_ALL

#define REG_ALL   0

Definition at line 94 of file LTC681x.h.

◆ SELFTEST_1

#define SELFTEST_1   1

Definition at line 77 of file LTC681x.h.

◆ SELFTEST_2

#define SELFTEST_2   2

Definition at line 78 of file LTC681x.h.

◆ STAT

#define STAT   3

Definition at line 111 of file LTC681x.h.

◆ STAT_CH_ALL

#define STAT_CH_ALL   0

Definition at line 88 of file LTC681x.h.

◆ STAT_CH_ITEMP

#define STAT_CH_ITEMP   2

Definition at line 90 of file LTC681x.h.

◆ STAT_CH_SOC

#define STAT_CH_SOC   1

Definition at line 89 of file LTC681x.h.

◆ STAT_CH_VREGA

#define STAT_CH_VREGA   3

Definition at line 91 of file LTC681x.h.

◆ STAT_CH_VREGD

#define STAT_CH_VREGD   4

Definition at line 92 of file LTC681x.h.

Variable Documentation

◆ PROGMEM

const uint16_t crc15Table [256] PROGMEM
Initial value:
= {0x0,0xc599, 0xceab, 0xb32, 0xd8cf, 0x1d56, 0x1664, 0xd3fd, 0xf407, 0x319e, 0x3aac,
0xff35, 0x2cc8, 0xe951, 0xe263, 0x27fa, 0xad97, 0x680e, 0x633c, 0xa6a5, 0x7558, 0xb0c1,
0xbbf3, 0x7e6a, 0x5990, 0x9c09, 0x973b, 0x52a2, 0x815f, 0x44c6, 0x4ff4, 0x8a6d, 0x5b2e,
0x9eb7, 0x9585, 0x501c, 0x83e1, 0x4678, 0x4d4a, 0x88d3, 0xaf29, 0x6ab0, 0x6182, 0xa41b,
0x77e6, 0xb27f, 0xb94d, 0x7cd4, 0xf6b9, 0x3320, 0x3812, 0xfd8b, 0x2e76, 0xebef, 0xe0dd,
0x2544, 0x2be, 0xc727, 0xcc15, 0x98c, 0xda71, 0x1fe8, 0x14da, 0xd143, 0xf3c5, 0x365c,
0x3d6e, 0xf8f7,0x2b0a, 0xee93, 0xe5a1, 0x2038, 0x7c2, 0xc25b, 0xc969, 0xcf0, 0xdf0d,
0x1a94, 0x11a6, 0xd43f, 0x5e52, 0x9bcb, 0x90f9, 0x5560, 0x869d, 0x4304, 0x4836, 0x8daf,
0xaa55, 0x6fcc, 0x64fe, 0xa167, 0x729a, 0xb703, 0xbc31, 0x79a8, 0xa8eb, 0x6d72, 0x6640,
0xa3d9, 0x7024, 0xb5bd, 0xbe8f, 0x7b16, 0x5cec, 0x9975, 0x9247, 0x57de, 0x8423, 0x41ba,
0x4a88, 0x8f11, 0x57c, 0xc0e5, 0xcbd7, 0xe4e, 0xddb3, 0x182a, 0x1318, 0xd681, 0xf17b,
0x34e2, 0x3fd0, 0xfa49, 0x29b4, 0xec2d, 0xe71f, 0x2286, 0xa213, 0x678a, 0x6cb8, 0xa921,
0x7adc, 0xbf45, 0xb477, 0x71ee, 0x5614, 0x938d, 0x98bf, 0x5d26, 0x8edb, 0x4b42, 0x4070,
0x85e9, 0xf84, 0xca1d, 0xc12f, 0x4b6, 0xd74b, 0x12d2, 0x19e0, 0xdc79, 0xfb83, 0x3e1a, 0x3528,
0xf0b1, 0x234c, 0xe6d5, 0xede7, 0x287e, 0xf93d, 0x3ca4, 0x3796, 0xf20f, 0x21f2, 0xe46b, 0xef59,
0x2ac0, 0xd3a, 0xc8a3, 0xc391, 0x608, 0xd5f5, 0x106c, 0x1b5e, 0xdec7, 0x54aa, 0x9133, 0x9a01,
0x5f98, 0x8c65, 0x49fc, 0x42ce, 0x8757, 0xa0ad, 0x6534, 0x6e06, 0xab9f, 0x7862, 0xbdfb, 0xb6c9,
0x7350, 0x51d6, 0x944f, 0x9f7d, 0x5ae4, 0x8919, 0x4c80, 0x47b2, 0x822b, 0xa5d1, 0x6048, 0x6b7a,
0xaee3, 0x7d1e, 0xb887, 0xb3b5, 0x762c, 0xfc41, 0x39d8, 0x32ea, 0xf773, 0x248e, 0xe117, 0xea25,
0x2fbc, 0x846, 0xcddf, 0xc6ed, 0x374, 0xd089, 0x1510, 0x1e22, 0xdbbb, 0xaf8, 0xcf61, 0xc453,
0x1ca, 0xd237, 0x17ae, 0x1c9c, 0xd905, 0xfeff, 0x3b66, 0x3054, 0xf5cd, 0x2630, 0xe3a9, 0xe89b,
0x2d02, 0xa76f, 0x62f6, 0x69c4, 0xac5d, 0x7fa0, 0xba39, 0xb10b, 0x7492, 0x5368, 0x96f1, 0x9dc3,
0x585a, 0x8ba7, 0x4e3e, 0x450c, 0x8095
}

Definition at line 798 of file LTC681x.h.