123 md_bits = (MD & 0x02) >> 1;
124 ADCV[0] = md_bits + 0x02;
125 md_bits = (MD & 0x01) << 7;
126 ADCV[1] = md_bits + 0x60 + (DCP<<4) + CH;
128 md_bits = (MD & 0x02) >> 1;
129 ADAX[0] = md_bits + 0x04;
130 md_bits = (MD & 0x01) << 7;
131 ADAX[1] = md_bits + 0x60 + CHG ;
166 cmd[2] = (uint8_t)(cmd_pec >> 8);
167 cmd[3] = (uint8_t)(cmd_pec);
214 cmd[2] = (uint8_t)(cmd_pec >> 8);
215 cmd[3] = (uint8_t)(cmd_pec);
275 const uint8_t BYT_IN_REG = 6;
276 const uint8_t CELL_IN_REG = 3;
279 uint8_t pec_error = 0;
280 uint16_t parsed_cell;
281 uint16_t received_pec;
283 uint8_t data_counter=0;
284 cell_data = (uint8_t *) malloc((NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
289 for (uint8_t cell_reg = 1; cell_reg<5; cell_reg++)
294 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
299 for (uint8_t current_cell = 0; current_cell<CELL_IN_REG; current_cell++)
303 parsed_cell = cell_data[data_counter] + (cell_data[data_counter + 1] << 8);
306 cell_codes[current_ic][current_cell + ((cell_reg - 1) * CELL_IN_REG)] = parsed_cell;
307 data_counter = data_counter + 2;
311 received_pec = (cell_data[data_counter] << 8) + cell_data[data_counter+1];
313 data_pec =
pec15_calc(BYT_IN_REG, &cell_data[current_ic * NUM_RX_BYT]);
314 if (received_pec != data_pec)
319 data_counter=data_counter+2;
329 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
333 for (uint8_t current_cell = 0; current_cell < CELL_IN_REG; current_cell++)
337 parsed_cell = cell_data[data_counter] + (cell_data[data_counter+1]<<8);
340 cell_codes[current_ic][current_cell + ((reg - 1) * CELL_IN_REG)] = 0x0000FFFF & parsed_cell;
341 data_counter= data_counter + 2;
345 received_pec = (cell_data[data_counter] << 8 )+ cell_data[data_counter + 1];
347 data_pec =
pec15_calc(BYT_IN_REG, &cell_data[current_ic * NUM_RX_BYT]);
348 if (received_pec != data_pec)
353 data_counter= data_counter + 2;
415 const uint8_t REG_LEN = 8;
443 cmd[2] = (uint8_t)(cmd_pec >> 8);
444 cmd[3] = (uint8_t)(cmd_pec);
503 const uint8_t BYT_IN_REG = 6;
504 const uint8_t GPIO_IN_REG = 3;
507 uint8_t data_counter = 0;
508 int8_t pec_error = 0;
510 uint16_t received_pec;
512 data = (uint8_t *) malloc((NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
517 for (uint8_t gpio_reg = 1; gpio_reg<3; gpio_reg++)
522 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
527 for (uint8_t current_gpio = 0; current_gpio< GPIO_IN_REG; current_gpio++)
531 parsed_aux = data[data_counter] + (data[data_counter+1]<<8);
534 aux_codes[current_ic][current_gpio +((gpio_reg-1)*GPIO_IN_REG)] = parsed_aux;
535 data_counter=data_counter+2;
540 received_pec = (data[data_counter]<<8)+ data[data_counter+1];
542 data_pec =
pec15_calc(BYT_IN_REG, &data[current_ic*NUM_RX_BYT]);
543 if (received_pec != data_pec)
549 data_counter=data_counter+2;
561 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
566 for (
int current_gpio = 0; current_gpio<GPIO_IN_REG; current_gpio++)
570 parsed_aux = (data[data_counter] + (data[data_counter+1]<<8));
572 aux_codes[current_ic][current_gpio +((reg-1)*GPIO_IN_REG)] = parsed_aux;
573 data_counter=data_counter+2;
577 received_pec = (data[data_counter]<<8) + data[data_counter+1];
579 data_pec =
pec15_calc(BYT_IN_REG, &data[current_ic*NUM_RX_BYT]);
580 if (received_pec != data_pec)
586 data_counter=data_counter+2;
643 const uint8_t REG_LEN = 8;
665 cmd[2] = (uint8_t)(cmd_pec >> 8);
666 cmd[3] = (uint8_t)(cmd_pec);
710 cmd[2] = (uint8_t)(cmd_pec >> 8);
711 cmd[3] = (uint8_t)(cmd_pec );
757 cmd[2] = (uint8_t)(cmd_pec >> 8);
758 cmd[3] = (uint8_t)(cmd_pec);
809 const uint8_t BYTES_IN_REG = 6;
810 const uint8_t CMD_LEN = 4+(8*total_ic);
815 cmd = (uint8_t *)malloc(CMD_LEN*
sizeof(uint8_t));
825 for (uint8_t current_ic = total_ic; current_ic > 0; current_ic--)
830 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
834 cmd[cmd_index] = config[current_ic-1][current_byte];
835 cmd_index = cmd_index + 1;
838 cfg_pec = (uint16_t)
pec15_calc(BYTES_IN_REG, &config[current_ic-1][0]);
839 cmd[cmd_index] = (uint8_t)(cfg_pec >> 8);
840 cmd[cmd_index + 1] = (uint8_t)cfg_pec;
841 cmd_index = cmd_index + 2;
892 uint8_t r_config[][8]
895 const uint8_t BYTES_IN_REG = 8;
899 int8_t pec_error = 0;
901 uint16_t received_pec;
903 rx_data = (uint8_t *) malloc((8*total_ic)*
sizeof(uint8_t));
918 for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++)
923 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
925 r_config[current_ic][current_byte] = rx_data[current_byte + (current_ic*BYTES_IN_REG)];
928 received_pec = (r_config[current_ic][6]<<8) + r_config[current_ic][7];
929 data_pec =
pec15_calc(6, &r_config[current_ic][0]);
930 if (received_pec != data_pec)
960 delayMicroseconds(2);
989 uint16_t remainder,addr;
992 for (uint8_t
i = 0;
i<len;
i++)
994 addr = ((remainder>>7)^data[
i])&0xff;
1012 for (uint8_t
i = 0;
i < len;
i++)
1034 for (uint8_t
i = 0;
i < tx_len;
i++)
1040 for (uint8_t
i = 0;
i < rx_len;
i++)
int8_t LTC6804_rdcfg(uint8_t total_ic, uint8_t r_config[][8])
uint8_t ADCV[2]
6804 conversion command variables.
int8_t LTC6804_rdaux(uint8_t reg, uint8_t total_ic, uint16_t aux_codes[][6])
Reads and parses the LTC6804 auxiliary registers.
#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 ...
uint8_t ADAX[2]
GPIO conversion command.
void LTC6804_clrcell()
Clears the LTC6804 cell voltage registers.
#define output_high(pin)
Set "pin" high.
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.
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_clraux()
Clears the LTC6804 Auxiliary registers.
void LTC6804_initialize()
This function will initialize all 6804 variables and the SPI port.
void LTC6804_rdcv_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Read the raw data from the LTC6804 cell voltage register.
union LT_union_int32_4bytes data
static const unsigned int crc15Table[256]
#define output_low(pin)
Set "pin" low.
uint16_t pec15_calc(uint8_t len, uint8_t *data)
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
void LTC6804_rdaux_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Read the raw data from the LTC6804 auxiliary register.
void set_adc(uint8_t MD, uint8_t DCP, uint8_t CH, uint8_t CHG)
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.
static uint16_t aux_codes[TOTAL_IC][6]
The GPIO codes will be stored in the aux_codes[][6] array in the following format: ...
LTC6804-1 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_wrcfg(uint8_t total_ic, uint8_t config[][6])
Write the LTC6804 configuration register.
void spi_write_array(uint8_t len, uint8_t data[])
Writes an array of bytes out of the SPI port.
static uint16_t cell_codes[TOTAL_IC][12]
The cell codes will be stored in the cell_codes[][12] array in the following format: ...