125 md_bits = (MD & 0x02) >> 1;
126 ADCV[0] = md_bits + 0x02;
127 md_bits = (MD & 0x01) << 7;
128 ADCV[1] = md_bits + 0x60 + (DCP<<4) + CH;
130 md_bits = (MD & 0x02) >> 1;
131 ADAX[0] = md_bits + 0x04;
132 md_bits = (MD & 0x01) << 7;
133 ADAX[1] = md_bits + 0x60 + CHG ;
162 cmd[2] = (uint8_t)(temp_pec >> 8);
163 cmd[3] = (uint8_t)(temp_pec);
203 cmd[2] = (uint8_t)(temp_pec >> 8);
204 cmd[3] = (uint8_t)(temp_pec);
264 const uint8_t BYT_IN_REG = 6;
265 const uint8_t CELL_IN_REG = 3;
268 int8_t pec_error = 0;
269 uint16_t parsed_cell;
270 uint16_t received_pec;
272 uint8_t data_counter=0;
273 cell_data = (uint8_t *) malloc((NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
278 for (uint8_t cell_reg = 1; cell_reg<5; cell_reg++)
282 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
286 for (uint8_t current_cell = 0; current_cell<CELL_IN_REG; current_cell++)
289 parsed_cell = cell_data[data_counter] + (cell_data[data_counter + 1] << 8);
290 cell_codes[current_ic][current_cell + ((cell_reg - 1) * CELL_IN_REG)] = parsed_cell;
291 data_counter = data_counter + 2;
294 received_pec = (cell_data[data_counter] << 8) + cell_data[data_counter+1];
295 data_pec =
pec15_calc(BYT_IN_REG, &cell_data[current_ic * NUM_RX_BYT ]);
296 if (received_pec != data_pec)
300 data_counter=data_counter+2;
310 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
314 for (uint8_t current_cell = 0; current_cell < CELL_IN_REG; current_cell++)
317 parsed_cell = cell_data[data_counter] + (cell_data[data_counter+1]<<8);
318 cell_codes[current_ic][current_cell + ((reg - 1) * CELL_IN_REG)] = 0x0000FFFF & parsed_cell;
319 data_counter= data_counter + 2;
322 received_pec = (cell_data[data_counter] << 8 )+ cell_data[data_counter + 1];
323 data_pec =
pec15_calc(BYT_IN_REG, &cell_data[current_ic * NUM_RX_BYT]);
324 if (received_pec != data_pec)
408 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
410 cmd[0] = 0x80 + (current_ic<<3);
412 cmd[2] = (uint8_t)(temp_pec >> 8);
413 cmd[3] = (uint8_t)(temp_pec);
467 const uint8_t BYT_IN_REG = 6;
468 const uint8_t GPIO_IN_REG = 3;
471 uint8_t data_counter = 0;
472 int8_t pec_error = 0;
473 uint16_t received_pec;
475 data = (uint8_t *) malloc((NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
480 for (uint8_t gpio_reg = 1; gpio_reg<3; gpio_reg++)
484 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
488 for (uint8_t current_gpio = 0; current_gpio< GPIO_IN_REG; current_gpio++)
491 aux_codes[current_ic][current_gpio +((gpio_reg-1)*GPIO_IN_REG)] = data[data_counter] + (data[data_counter+1]<<8);
492 data_counter=data_counter+2;
496 received_pec = (data[data_counter]<<8)+ data[data_counter+1];
497 data_pec =
pec15_calc(BYT_IN_REG, &data[current_ic*NUM_RX_BYT]);
498 if (received_pec != data_pec)
503 data_counter=data_counter+2;
514 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
518 for (
int current_gpio = 0; current_gpio<GPIO_IN_REG; current_gpio++)
521 aux_codes[current_ic][current_gpio +((reg-1)*GPIO_IN_REG)] = 0x0000FFFF & (data[data_counter] + (data[data_counter+1]<<8));
522 data_counter=data_counter+2;
525 received_pec = (data[data_counter]<<8) + data[data_counter+1];
526 data_pec =
pec15_calc(6, &data[current_ic*8]);
527 if (received_pec != data_pec)
596 cmd[2] = (uint8_t)(cmd_pec >> 8);
597 cmd[3] = (uint8_t)(cmd_pec);
602 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
604 cmd[0] = 0x80 + (current_ic<<3);
606 cmd[2] = (uint8_t)(cmd_pec >> 8);
607 cmd[3] = (uint8_t)(cmd_pec);
639 cmd[2] = (uint8_t)(cmd_pec >> 8);
640 cmd[3] = (uint8_t)(cmd_pec );
678 cmd[2] = (uint8_t)(cmd_pec >> 8);
679 cmd[3] = (uint8_t)(cmd_pec);
720 const uint8_t BYTES_IN_REG = 6;
721 const uint8_t CMD_LEN = 4+(8*total_ic);
726 cmd = (uint8_t *)malloc(CMD_LEN*
sizeof(uint8_t));
735 for (uint8_t current_ic = 0; current_ic < total_ic ; current_ic++)
737 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
741 cmd[cmd_index] = config[current_ic][current_byte];
742 cmd_index = cmd_index + 1;
745 temp_pec = (uint16_t)
pec15_calc(BYTES_IN_REG, &config[current_ic][0]);
746 cmd[cmd_index] = (uint8_t)(temp_pec >> 8);
747 cmd[cmd_index + 1] = (uint8_t)temp_pec;
748 cmd_index = cmd_index + 2;
754 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
756 cmd[0] = 0x80 + (current_ic<<3);
758 cmd[2] = (uint8_t)(temp_pec >> 8);
759 cmd[3] = (uint8_t)(temp_pec);
800 const uint8_t BYTES_IN_REG = 8;
804 int8_t pec_error = 0;
806 uint16_t received_pec;
807 rx_data = (uint8_t *) malloc((8*total_ic)*
sizeof(uint8_t));
817 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
819 cmd[0] = 0x80 + (current_ic<<3);
821 cmd[2] = (uint8_t)(data_pec >> 8);
822 cmd[3] = (uint8_t)(data_pec);
828 for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++)
831 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
833 r_config[current_ic][current_byte] = rx_data[current_byte + (current_ic*BYTES_IN_REG)];
836 received_pec = (r_config[current_ic][6]<<8) + r_config[current_ic][7];
837 data_pec =
pec15_calc(6, &r_config[current_ic][0]);
838 if (received_pec != data_pec)
865 delayMicroseconds(10);
893 uint16_t remainder,addr;
896 for (uint8_t
i = 0;
i<len;
i++)
898 addr = ((remainder>>7)^data[
i])&0xff;
916 for (uint8_t
i = 0;
i < len;
i++)
937 for (uint8_t
i = 0;
i < tx_len;
i++)
943 for (uint8_t
i = 0;
i < rx_len;
i++)
uint8_t ADAX[2]
GPIO conversion command.
#define CELL_CH_ALL
CH Dec Channels to convert 0000 All Cells 0011 Cell 1 and Cell 7 0102 Cell 2 and Cell 8 0113 Cell 3 ...
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.
#define output_high(pin)
Set "pin" high.
void spi_write_array(uint8_t len, uint8_t data[])
Writes an array of bytes out of the SPI port.
int8_t LTC6804_rdaux(uint8_t reg, uint8_t total_ic, uint16_t aux_codes[][6])
Reads and parses the LTC6804 auxiliary registers.
Header File for Linduino Libraries and Demo Code.
void spi_write(int8_t data)
Write a data byte using the SPI hardware.
#define AUX_CH_ALL
CHG Dec Channels to convert 000 0 All GPIOS and 2nd Ref 001 1 GPIO 1 010 2 GPIO 2 011 3 GPIO 3 100 4...
void spi_enable(uint8_t spi_clock_divider)
Setup the processor for hardware SPI communication.
void LTC6804_clrcell()
Clears the LTC6804 cell voltage registers.
void set_adc(uint8_t MD, uint8_t DCP, uint8_t CH, uint8_t CHG)
union LT_union_int32_4bytes data
uint16_t pec15_calc(uint8_t len, uint8_t *data)
static const unsigned int crc15Table[256]
void LTC6804_rdcv_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Read the raw data from the LTC6804 cell voltage register.
#define output_low(pin)
Set "pin" low.
void LTC6804_wrcfg(uint8_t total_ic, uint8_t config[][6])
Write the LTC6804 configuration register.
LTC6804-2 Multicell Battery Monitor.
uint8_t LTC6804_rdcv(uint8_t reg, uint8_t total_ic, uint16_t cell_codes[][12])
Reads and parses the LTC6804 cell voltage registers.
void LTC6804_initialize()
This function will initialize all 6804 variables and the SPI port.
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
int8_t spi_read(int8_t data)
The data byte to be written.
int8_t LTC6804_rdcfg(uint8_t total_ic, uint8_t r_config[][8])
static uint16_t aux_codes[TOTAL_IC][6]
The GPIO codes will be stored in the aux_codes[][6] array in the following format: ...
void LTC6804_clraux()
Clears the LTC6804 Auxiliary registers.
uint8_t ADCV[2]
6804 conversion command variables.
static uint16_t cell_codes[TOTAL_IC][12]
The cell codes will be stored in the cell_codes[][12] array in the following format: ...
void LTC6804_rdaux_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Read the raw data from the LTC6804 auxiliary register.