DC2100A  1.2.0
Bi-Directional Cell Balancer Using the LTC3300-1 and the LTC6804-2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LTC6804-2.c File Reference

Driver File for LTC6804-2 Multicell Battery Monitors. More...

Go to the source code of this file.

Detailed Description

Driver File for LTC6804-2 Multicell Battery Monitors.

Definition in file LTC6804-2.c.

Functions

void ltc6804_wakeup (void)
 
void ltc6804_get_adcopt_and_md (int8 conversion_mode, int8 *adcopt_ptr, int8 *md_ptr)
 
void ltc6804_adc_opt_set (int8 board_num, int8 adcopt)
 
void ltc6804_command_code_send (int16 command_code, BOOLEAN reg_group_command)
 
void ltc6804_register_group_write (int8 *register_group)
 
BOOLEAN ltc6804_register_group_read (int8 *register_group)
 
void ltc6804_cfgr_modify (int8 board_num, int8 *register_mask_ptr, int8 *register_value_ptr)
 
void ltc6804_clock_out (int16 bytes_to_send, int16 baud_khz)
 
unsigned int16 ltc6804_pec_lookup (char data, unsigned int16 remainder)
 
void LTC6804_Init (void)
 Initializes the LTC6804-2 code module. More...
 
void LTC6804_GPIO_Set (int8 board_num, int8 gpio_bitmap)
 Sets the LTC6804 GPIO Pull Downs. More...
 
void LTC6804_Refon_Set (int8 board_num, BOOLEAN refon)
 Turns the LTC6804 ADC Reference on and off. More...
 
void LTC6804_UVOV_Thresholds_Set (int8 board_num, int16 vuv_value, int16 vov_value)
 Sets the LTC6804 under-voltage and over-voltage thresholds in LTC6804_UVOV_RESOLUTION units. More...
 
void LTC6804_Dischargers_Set (int8 board_num, int16 discharge_bitmap, int16 timeout_value)
 Sets the LTC6804 discharger pin levels and timeout values. More...
 
BOOLEAN LTC6804_UVOV_Thresholds_Get (int8 board_num, unsigned int16 *vuv_value, unsigned int16 *vov_value)
 Gets the LTC6804 under-voltage and over-voltage thresholds in LTC6804_UVOV_RESOLUTION units. More...
 
BOOLEAN LTC6804_UVOV_Flags_Get (int8 board_num, int16 *vuv_flags, int16 *vov_flags)
 Gets the LTC6804 flags indicating under-voltage and over-voltage conditions are present. More...
 
BOOLEAN LTC6804_Revision_Get (int8 board_num, unsigned int8 *revision)
 Gets the LTC6804 revision. More...
 
BOOLEAN LTC6804_Refon_Get (int8 board_num, int8 *refon)
 Gets the LTC6804 ADC Reference status, where 1 = ON and 0 = OFF. More...
 
void LTC6804_Cell_ADC_Clear (int8 board_num)
 Clears the LTC6804 Cell Voltage ADC registers. More...
 
void LTC6804_Cell_ADC_Start (int8 board_num, LTC6804_CONVERSION_MODE_T mode, LTC6804_CH_CELL_TYPE cell_select, BOOLEAN discharge_permitted)
 Starts the LTC6804 Cell Voltage ADC conversion at the specified conversion mode. More...
 
BOOLEAN LTC6804_Cell_ADC_Read (int8 board_num, LTC6804_CH_CELL_TYPE cell_select, unsigned int16 *adc_value_ptr)
 Reads the LTC6804 Cell Voltage ADC conversion results. More...
 
void LTC6804_GPIO_ADC_Clear (int8 board_num)
 Clears the LTC6804 GPIO ADC registers. More...
 
void LTC6804_GPIO_ADC_Start (int8 board_num, LTC6804_CONVERSION_MODE_T mode, LTC6804_CHG_GPIO_TYPE gpio_select)
 Starts the specified LTC6804 GPIO ADC conversion at the specified conversion mode. More...
 
BOOLEAN LTC6804_GPIO_ADC_Read (int8 board_num, LTC6804_CHG_GPIO_TYPE gpio_select, int16 *adc_value_ptr)
 Reads the specified LTC6804 GPIO ADC conversion results. More...
 
void LTC6804_I2C_Write (int8 board_num, BOOLEAN start, BOOLEAN stop, int8 *data_ptr, int16 num_bytes, int16 baud_khz)
 Writes a string of bytes to the LTC6804 I2C port implemented on its GPIO pins. More...
 
BOOLEAN LTC6804_I2C_Read (int8 board_num, BOOLEAN start, BOOLEAN stop, int8 *data_ptr, int16 num_bytes, int16 baud_khz)
 Writes one byte, and then reads a string of bytes to the LTC6804 I2C port implemented on its GPIO pins. More...
 
void LTC6804_SPI_Write (int8 board_num, BOOLEAN start, BOOLEAN stop, int8 *data_ptr, int16 num_bytes, int16 baud_khz)
 Writes a string of bytes to the LTC6804 SPI port implemented on its GPIO pins. More...
 
BOOLEAN LTC6804_SPI_Read (int8 board_num, BOOLEAN start, BOOLEAN stop, int8 *data_ptr, int16 num_bytes, int16 baud_khz)
 Writes one byte, and then reads a string of bytes to the LTC6804 SPI port implemented on its GPIO pins. More...
 
unsigned int16 LTC6804_PEC_Calc (char *data, int length)
 Calculates the LTC6804 CRC over a string of bytes as per datasheet figure 22. More...
 

Macros

#define LTC6804_TWAKE   300
 
#define LTC6804_TSLEEP   1800
 
#define LTC6804_TREADY   10
 
#define LTC6804_TIDLE   4300
 
#define LTC6804_TDWELL   1
 
#define LTC6804_NUM_CELLV_ADC_PER_REGISTER_GROUP   (LTC6804_REGISTER_GROUP_SIZE / LTC6804_ADC_SIZE)
 
#define LTC6804_NUM_REGISTER_GROUP_READS_FOR_ALL_CELLV   (LTC6804_NUM_CELLV_ADC / LTC6804_NUM_CELLV_ADC_PER_REGISTER_GROUP)
 
#define LTC6804_NUM_REGISTER_GROUP_READS_FOR_TWO_CELLV   (2)
 
#define LTC6804_NUM_AUX_ADC_PER_REGISTER_GROUP   (LTC6804_REGISTER_GROUP_SIZE / LTC6804_ADC_SIZE)
 
#define LTC6804_NUM_COMM_BYTES_PER_REGISTER_GROUP   3
 
#define LTC6804_SPI_CLOCK_CYCLES_PER_STCOMM_BYTE   24
 
#define LTC6804_SPI_BYTES_PER_STCOMM_BYTE   (LTC6804_SPI_CLOCK_CYCLES_PER_STCOMM_BYTE/BITS_PER_BYTE)
 
#define LTC6804_BAUD_RATE_DIVISOR   2
 

Variables

const unsigned int16 ltc6804_pec_seed_value = 16
 
const unsigned int16 ltc6804_pec_table [256]
 
unsigned int8 ltc6804_gpio_pulldown
 
int8 ltc6804_adcopt
 
unsigned int32 ltc6804_wakeup_timestamp
 

Function Documentation

void LTC6804_Cell_ADC_Clear ( int8  board_num)

Clears the LTC6804 Cell Voltage ADC registers.

This is useful to detect if the conversion was started properly when the results are read.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.

Definition at line 447 of file LTC6804-2.c.

BOOLEAN LTC6804_Cell_ADC_Read ( int8  board_num,
LTC6804_CH_CELL_TYPE  cell_select,
unsigned int16 *  adc_value_ptr 
)

Reads the LTC6804 Cell Voltage ADC conversion results.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
cell_selectThe cells that were converted.
adc_value_ptrPointer where up to LTC6804_NUM_CELLV_ADC cell voltages will be returned.

Definition at line 502 of file LTC6804-2.c.

void LTC6804_Cell_ADC_Start ( int8  board_num,
LTC6804_CONVERSION_MODE_T  mode,
LTC6804_CH_CELL_TYPE  cell_select,
BOOLEAN  discharge_permitted 
)

Starts the LTC6804 Cell Voltage ADC conversion at the specified conversion mode.

Note function always permits discharge.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
modeThe mode to use for ADC conversion.
cell_selectThe cells to convert.
discharge_permittedTrue if discharge is to be permitted during this cell voltage conversion.

Definition at line 468 of file LTC6804-2.c.

void LTC6804_Dischargers_Set ( int8  board_num,
int16  discharge_bitmap,
int16  timeout_value 
)

Sets the LTC6804 discharger pin levels and timeout values.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
discharge_bitmapbitmap for discharger, bit0 = cell 0.
timeout_valuetimeout value for dischargers.

Definition at line 256 of file LTC6804-2.c.

void LTC6804_GPIO_ADC_Clear ( int8  board_num)

Clears the LTC6804 GPIO ADC registers.

This is useful to detect if the conversion was started properly when the results are read.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.

Definition at line 578 of file LTC6804-2.c.

BOOLEAN LTC6804_GPIO_ADC_Read ( int8  board_num,
LTC6804_CHG_GPIO_TYPE  gpio_select,
int16 *  adc_value_ptr 
)

Reads the specified LTC6804 GPIO ADC conversion results.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
gpio_selectThe gpio that was converted.
adc_value_ptrPointer where up to LTC6804_NUM_GPIO GPIO ADC results will be returned.

Definition at line 633 of file LTC6804-2.c.

void LTC6804_GPIO_ADC_Start ( int8  board_num,
LTC6804_CONVERSION_MODE_T  mode,
LTC6804_CHG_GPIO_TYPE  gpio_select 
)

Starts the specified LTC6804 GPIO ADC conversion at the specified conversion mode.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
modeThe mode to use for ADC conversion.
gpio_selectThe gpio to convert from LTC6804_CHG GPIO Selections.

Definition at line 599 of file LTC6804-2.c.

void LTC6804_GPIO_Set ( int8  board_num,
int8  gpio_bitmap 
)

Sets the LTC6804 GPIO Pull Downs.

Write: 0 -> GPIOx Pin Pull-Down ON; 1-> GPIOx Pin Pull-Down OFF

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
gpio_bitmapbitmap for GPIO pull-downs, bit0 = GPIO 0

Definition at line 185 of file LTC6804-2.c.

BOOLEAN LTC6804_I2C_Read ( int8  board_num,
BOOLEAN  start,
BOOLEAN  stop,
int8 *  data_ptr,
int16  num_bytes,
int16  baud_khz 
)

Writes one byte, and then reads a string of bytes to the LTC6804 I2C port implemented on its GPIO pins.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
startTRUE if this read would be started by an I2C Start Condition.
stopTRUE if this read would be ended with an I2C Stop Condition.
data_ptrPointer to a byte to first write to the I2C Bus, and where to store the data read from the I2C Bus.
num_bytesThe number of bytes to read to the I2C Bus.
baud_khzThe baud rate at which the I2C Bus should be clocked.

Definition at line 763 of file LTC6804-2.c.

void LTC6804_I2C_Write ( int8  board_num,
BOOLEAN  start,
BOOLEAN  stop,
int8 *  data_ptr,
int16  num_bytes,
int16  baud_khz 
)

Writes a string of bytes to the LTC6804 I2C port implemented on its GPIO pins.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
startTRUE if this write would be started by an I2C Start Condition.
stopTRUE if this write would be ended with an I2C Stop Condition.
data_ptrPointer to the data to write to the I2C Bus.
num_bytesThe number of bytes to write to the I2C Bus.
baud_khzThe baud rate at which the I2C Bus should be clocked.

Definition at line 703 of file LTC6804-2.c.

void LTC6804_Init ( void  )

Initializes the LTC6804-2 code module.

Returns
void

Definition at line 170 of file LTC6804-2.c.

unsigned int16 LTC6804_PEC_Calc ( char *  data,
int  length 
)

Calculates the LTC6804 CRC over a string of bytes as per datasheet figure 22.

Returns
the calculated CRC
Parameters
dataPointer to the data to over which to calculate the CRC.
lengthThe number of bytes over which to calculate the CRC.

Definition at line 1009 of file LTC6804-2.c.

BOOLEAN LTC6804_Refon_Get ( int8  board_num,
int8 *  refon 
)

Gets the LTC6804 ADC Reference status, where 1 = ON and 0 = OFF.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
refonlocation where to return the ADC Reference status.

Definition at line 406 of file LTC6804-2.c.

void LTC6804_Refon_Set ( int8  board_num,
BOOLEAN  refon 
)

Turns the LTC6804 ADC Reference on and off.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
refonTRUE to turn on the reference, FALSE to turn it off.

Definition at line 206 of file LTC6804-2.c.

BOOLEAN LTC6804_Revision_Get ( int8  board_num,
unsigned int8 *  revision 
)

Gets the LTC6804 revision.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
revisionPointer where to return revision.

Definition at line 373 of file LTC6804-2.c.

BOOLEAN LTC6804_SPI_Read ( int8  board_num,
BOOLEAN  start,
BOOLEAN  stop,
int8 *  data_ptr,
int16  num_bytes,
int16  baud_khz 
)

Writes one byte, and then reads a string of bytes to the LTC6804 SPI port implemented on its GPIO pins.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
startTRUE if the CS should be raised at the start of SPI communication.
stopTRUE if the CS should be lowered at the end of SPI communication.
data_ptrPointer to a byte to first write to the SPI Bus, and where to store the data read from the SPI Bus.
num_bytesThe number of bytes to write to the SPI Bus.
baud_khzThe baud rate at which the SPI Bus should be clocked.

Definition at line 912 of file LTC6804-2.c.

void LTC6804_SPI_Write ( int8  board_num,
BOOLEAN  start,
BOOLEAN  stop,
int8 *  data_ptr,
int16  num_bytes,
int16  baud_khz 
)

Writes a string of bytes to the LTC6804 SPI port implemented on its GPIO pins.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
startTRUE if the CS should be raised at the start of SPI communication.
stopTRUE if the CS should be lowered at the end of SPI communication.
data_ptrPointer to the data to write to the SPI Bus.
num_bytesThe number of bytes to write to the SPI Bus.
baud_khzThe baud rate at which the SPI Bus should be clocked.

Definition at line 861 of file LTC6804-2.c.

BOOLEAN LTC6804_UVOV_Flags_Get ( int8  board_num,
int16 *  vuv_flags,
int16 *  vov_flags 
)

Gets the LTC6804 flags indicating under-voltage and over-voltage conditions are present.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
vuv_flagsPointer where to return under-voltage flags in a bitmap with bit 0 = cell 0.
vov_flagsPointer where to return over-voltage flags in a bitmap with bit 0 = cell 0.

Definition at line 316 of file LTC6804-2.c.

BOOLEAN LTC6804_UVOV_Thresholds_Get ( int8  board_num,
unsigned int16 *  vuv_value,
unsigned int16 *  vov_value 
)

Gets the LTC6804 under-voltage and over-voltage thresholds in LTC6804_UVOV_RESOLUTION units.

Returns
TRUE if the LTC6804 communication was successful.
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
vuv_valuePointer where to return under-voltage value.
vov_valuePointer where to return over-voltage value.

Definition at line 282 of file LTC6804-2.c.

void LTC6804_UVOV_Thresholds_Set ( int8  board_num,
int16  vuv_value,
int16  vov_value 
)

Sets the LTC6804 under-voltage and over-voltage thresholds in LTC6804_UVOV_RESOLUTION units.

Returns
void
Parameters
board_numThe logical address for the PCB containing this LTC6804-2 IC.
vuv_valueUnder-voltage value.
vov_valueOver-voltage value.

Definition at line 230 of file LTC6804-2.c.

Variable Documentation

const unsigned int16 ltc6804_pec_table[256]
Initial value:
=
{ 0x0000, 0xc599, 0xceab, 0x0b32, 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, 0x02be, 0xc727, 0xcc15, 0x098c, 0xda71, 0x1fe8, 0x14da, 0xd143, 0xf3c5, 0x365c,
0x3d6e, 0xf8f7, 0x2b0a, 0xee93, 0xe5a1, 0x2038, 0x07c2, 0xc25b, 0xc969, 0x0cf0, 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, 0x057c, 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, 0x0f84, 0xca1d, 0xc12f, 0x04b6, 0xd74b, 0x12d2, 0x19e0, 0xdc79, 0xfb83, 0x3e1a, 0x3528,
0xf0b1, 0x234c, 0xe6d5, 0xede7, 0x287e, 0xf93d, 0x3ca4, 0x3796, 0xf20f, 0x21f2, 0xe46b, 0xef59,
0x2ac0, 0x0d3a, 0xc8a3, 0xc391, 0x0608, 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, 0x0846, 0xcddf, 0xc6ed, 0x0374, 0xd089, 0x1510, 0x1e22, 0xdbbb, 0x0af8, 0xcf61, 0xc453,
0x01ca, 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 118 of file LTC6804-2.c.