![]() |
Linduino
1.3.0
Linear Technology Arduino-Compatible Demonstration Board
|
Library for LTC6804-1 Multicell Battery Monitor. More...
Library for LTC6804-1 Multicell Battery Monitor.
Definition in file LTC68041.cpp.
Go to the source code of this file.
Functions | |
void | LTC6804_initialize () |
This function will initialize all 6804 variables and the SPI port. More... | |
void | set_adc (uint8_t MD, uint8_t DCP, uint8_t CH, uint8_t CHG) |
More... | |
void | LTC6804_adcv () |
More... | |
void | LTC6804_adax () |
More... | |
uint8_t | LTC6804_rdcv (uint8_t reg, uint8_t total_ic, uint16_t cell_codes[][12]) |
Reads and parses the LTC6804 cell voltage registers. More... | |
void | LTC6804_rdcv_reg (uint8_t reg, uint8_t total_ic, uint8_t *data) |
Read the raw data from the LTC6804 cell voltage register. More... | |
int8_t | LTC6804_rdaux (uint8_t reg, uint8_t total_ic, uint16_t aux_codes[][6]) |
Reads and parses the LTC6804 auxiliary registers. More... | |
void | LTC6804_rdaux_reg (uint8_t reg, uint8_t total_ic, uint8_t *data) |
Read the raw data from the LTC6804 auxiliary register. More... | |
void | LTC6804_clrcell () |
Clears the LTC6804 cell voltage registers. More... | |
void | LTC6804_clraux () |
Clears the LTC6804 Auxiliary registers. More... | |
void | LTC6804_wrcfg (uint8_t total_ic, uint8_t config[][6]) |
Write the LTC6804 configuration register. More... | |
int8_t | LTC6804_rdcfg (uint8_t total_ic, uint8_t r_config[][8]) |
More... | |
void | wakeup_idle () |
More... | |
void | wakeup_sleep () |
More... | |
uint16_t | pec15_calc (uint8_t len, uint8_t *data) |
More... | |
void | spi_write_array (uint8_t len, uint8_t data[]) |
Writes an array of bytes out of the SPI port. More... | |
void | spi_write_read (uint8_t tx_Data[], uint8_t tx_len, uint8_t *rx_data, uint8_t rx_len) |
Writes and read a set number of bytes using the SPI port. More... | |
Variables | |
uint8_t | ADCV [2] |
6804 conversion command variables. More... | |
uint8_t | ADAX [2] |
GPIO conversion command. More... | |
void LTC6804_adax | ( | ) |
Start an GPIO Conversion
Starts an ADC conversions of the LTC6804 GPIO inputs. The type of ADC conversion executed can be changed by setting the associated global variables:
Variable | Function |
---|---|
MD | Determines the filter corner of the ADC |
CHG | Determines which GPIO channels are converted |
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ADAX: | 0 | 0 | 0 | 0 | 0 | 1 | 0 | MD[1] | MD[2] | 1 | 1 | DCP | 0 | CHG[2] | CHG[1] | CHG[0] |
Definition at line 206 of file LTC68041.cpp.
void LTC6804_adcv | ( | ) |
Starts cell voltage conversion
Starts ADC conversions of the LTC6804 Cpin inputs. The type of ADC conversion executed can be changed by setting the associated global variables:
Variable | Function |
---|---|
MD | Determines the filter corner of the ADC |
CH | Determines which cell channels are converted |
DCP | Determines if Discharge is Permitted |
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ADCV: | 0 | 0 | 0 | 0 | 0 | 0 | 1 | MD[1] | MD[2] | 1 | 1 | DCP | 0 | CH[2] | CH[1] | CH[0] |
Definition at line 154 of file LTC68041.cpp.
void LTC6804_clraux | ( | ) |
Clears the LTC6804 Auxiliary registers.
The command clears the Auxiliary registers and intiallizes all values to 1. The register will read back hexadecimal 0xFF after the command is sent.
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CLRAUX: | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 2 | 0 |
Definition at line 746 of file LTC68041.cpp.
void LTC6804_clrcell | ( | ) |
Clears the LTC6804 cell voltage registers.
The command clears the cell voltage registers and intiallizes all values to 1. The register will read back hexadecimal 0xFF after the command is sent.
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CLRCELL: | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
Definition at line 699 of file LTC68041.cpp.
void LTC6804_initialize | ( | ) |
This function will initialize all 6804 variables and the SPI port.
This function will initialize the Linduino to communicate with the LTC6804 with a 1MHz SPI clock. The Function also intializes the ADCV and ADAX commands to convert all cell and GPIO voltages in the Normal ADC mode.
Definition at line 92 of file LTC68041.cpp.
int8_t LTC6804_rdaux | ( | uint8_t | reg, |
uint8_t | total_ic, | ||
uint16_t | aux_codes[][6] | ||
) |
Reads and parses the LTC6804 auxiliary registers.
The function is used to read the parsed GPIO codes of the LTC6804. This function will send the requested read commands parse the data and store the gpio voltages in aux_codes variable
[in] | uint8_t | reg; This controls which GPIO voltage register is read back. 0: Read back all auxiliary registers 1: Read back auxiliary group A 2: Read back auxiliary group B | ||||||||||||||||||
[in] | uint8_t | total_ic; This is the number of ICs in the daisy chain(-1 only) | ||||||||||||||||||
[out] | uint16_t | aux_codes[][6]; A two dimensional array of the gpio voltage codes. The GPIO codes will be stored in the aux_codes[][6] array in the following format:
|
0: No PEC error detected
-1: PEC error detected, retry read
Definition at line 495 of file LTC68041.cpp.
void LTC6804_rdaux_reg | ( | uint8_t | reg, |
uint8_t | total_ic, | ||
uint8_t * | data | ||
) |
Read the raw data from the LTC6804 auxiliary register.
The function reads a single GPIO voltage register and stores thre read data in the *data point as a byte array. This function is rarely used outside of the LTC6804_rdaux() command.
[in] | uint8_t | reg; This controls which GPIO voltage register is read back. 1: Read back auxiliary group A 2: Read back auxiliary group B |
[in] | uint8_t | total_ic; This is the number of ICs in the daisy chain |
[out] | uint8_t | *data; An array of the unparsed aux codes |
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
RDAUXA: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
RDAUXB: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
Definition at line 638 of file LTC68041.cpp.
int8_t LTC6804_rdcfg | ( | uint8_t | total_ic, |
uint8_t | r_config[][8] | ||
) |
Reads configuration registers of a LTC6804 daisy chain
[in] | uint8_t | total_ic: number of ICs in the daisy chain |
[out] | uint8_t | r_config[][8] is a two dimensional array that the function stores the read configuration data. The configuration data for each IC is stored in blocks of 8 bytes with the configuration data of the lowest IC on the stack in the first 8 bytes block of the array, the second IC in the second 8 byte etc. Below is an table illustrating the array organization: |
r_config[0][0] | r_config[0][1] | r_config[0][2] | r_config[0][3] | r_config[0][4] | r_config[0][5] | r_config[0][6] | r_config[0][7] | r_config[1][0] | r_config[1][1] | ..... |
---|---|---|---|---|---|---|---|---|---|---|
IC1 CFGR0 | IC1 CFGR1 | IC1 CFGR2 | IC1 CFGR3 | IC1 CFGR4 | IC1 CFGR5 | IC1 PEC High | IC1 PEC Low | IC2 CFGR0 | IC2 CFGR1 | ..... |
0: Data read back has matching PEC
-1: Data read back has incorrect PEC
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
RDCFG: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
Definition at line 891 of file LTC68041.cpp.
uint8_t LTC6804_rdcv | ( | uint8_t | reg, |
uint8_t | total_ic, | ||
uint16_t | cell_codes[][12] | ||
) |
Reads and parses the LTC6804 cell voltage registers.
The function is used to read the cell codes of the LTC6804. This function will send the requested read commands parse the data and store the cell voltages in cell_codes variable.
[in] | uint8_t | reg; This controls which cell voltage register is read back. 0: Read back all Cell registers 1: Read back cell group A 2: Read back cell group B 3: Read back cell group C 4: Read back cell group D | ||||||||||||||||
[in] | uint8_t | total_ic; This is the number of ICs in the daisy chain(-1 only) | ||||||||||||||||
[out] | uint16_t | cell_codes[]; An array of the parsed cell codes from lowest to highest. The cell codes will be stored in the cell_codes[] array in the following format:
|
0: No PEC error detected
-1: PEC error detected, retry read
Definition at line 268 of file LTC68041.cpp.
void LTC6804_rdcv_reg | ( | uint8_t | reg, |
uint8_t | total_ic, | ||
uint8_t * | data | ||
) |
Read the raw data from the LTC6804 cell voltage register.
The function reads a single cell voltage register and stores the read data in the *data point as a byte array. This function is rarely used outside of the LTC6804_rdcv() command.
[in] | uint8_t | reg; This controls which cell voltage register is read back. 1: Read back cell group A 2: Read back cell group B 3: Read back cell group C 4: Read back cell group D |
[in] | uint8_t | total_ic; This is the number of ICs in the daisy chain(-1 only) |
[out] | uint8_t | *data; An array of the unparsed cell codes |
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
RDCVA: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
RDCVB: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
RDCVC: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
RDCVD: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
Definition at line 410 of file LTC68041.cpp.
void LTC6804_wrcfg | ( | uint8_t | total_ic, |
uint8_t | config[][6] | ||
) |
Write the LTC6804 configuration register.
This command will write the configuration registers of the LTC6804-1s connected in a daisy chain stack. The configuration is written in descending order so the last device's configuration is written first.
[in] | uint8_t | total_ic; The number of ICs being written to. | ||||||||||||||||||||
[in] | uint8_t | config[][6] is a two dimensional array of the configuration data that will be written, the array should contain the 6 bytes for each IC in the daisy chain. The lowest IC in the daisy chain should be the first 6 byte block in the array. The array should have the following format:
|
| | CMD[0] | CMD[1] | |------------—|------------------------------------------------------------—|------------------------------------------------------------—|
CMD[0:1] | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WRCFG: | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
Definition at line 805 of file LTC68041.cpp.
uint16_t pec15_calc | ( | uint8_t | len, |
uint8_t * | data | ||
) |
Calculates and returns the CRC15.
calaculates and returns the CRC15
[in] | uint8_t | len: the length of the data array being passed to the function |
[in] | uint8_t | data[] : the array of data that the PEC will be generated from |
len | The length of the data array being passed to the function |
data | The array of data that the PEC will be generated from |
Definition at line 985 of file LTC68041.cpp.
void set_adc | ( | uint8_t | MD, |
uint8_t | DCP, | ||
uint8_t | CH, | ||
uint8_t | CHG | ||
) |
Maps global ADC control variables to the appropriate control bytes for each of the different ADC commands
[in] | uint8_t | MD The adc conversion mode |
[in] | uint8_t | DCP Controls if Discharge is permitted during cell conversions |
[in] | uint8_t | CH Determines which cells are measured during an ADC conversion command |
[in] | uint8_t | CHG Determines which GPIO channels are measured during Auxiliary conversion command |
command | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ADCV: | 0 | 0 | 0 | 0 | 0 | 0 | 1 | MD[1] | MD[2] | 1 | 1 | DCP | 0 | CH[2] | CH[1] | CH[0] |
ADAX: | 0 | 0 | 0 | 0 | 0 | 1 | 0 | MD[1] | MD[2] | 1 | 1 | DCP | 0 | CHG[2] | CHG[1] | CHG[0] |
Definition at line 115 of file LTC68041.cpp.
void spi_write_array | ( | uint8_t | len, |
uint8_t | data[] | ||
) |
Writes an array of bytes out of the SPI port.
[in] | uint8_t | len length of the data array being written on the SPI port |
[in] | uint8_t | data[] the data array to be written on the SPI port |
Definition at line 1008 of file LTC68041.cpp.
void spi_write_read | ( | uint8_t | tx_Data[], |
uint8_t | tx_len, | ||
uint8_t * | rx_data, | ||
uint8_t | rx_len | ||
) |
Writes and read a set number of bytes using the SPI port.
[in] | uint8_t | tx_data[] array of data to be written on the SPI port |
[in] | uint8_t | tx_len length of the tx_data array |
[out] | uint8_t | rx_data array that read data will be written too. |
[in] | uint8_t | rx_len number of bytes to be read from the SPI port. |
Definition at line 1028 of file LTC68041.cpp.
void wakeup_idle | ( | ) |
Wake isoSPI up from idle state Generic wakeup commannd to wake isoSPI up out of idle
Definition at line 957 of file LTC68041.cpp.
void wakeup_sleep | ( | ) |
Wake the LTC6804 from the sleep state
Generic wakeup commannd to wake the LTC6804 from sleep
Definition at line 969 of file LTC68041.cpp.
uint8_t ADAX[2] |
GPIO conversion command.
Definition at line 82 of file LTC68041.cpp.
uint8_t ADCV[2] |
6804 conversion command variables.
Cell Voltage conversion command.
Definition at line 81 of file LTC68041.cpp.