92 uint8_t BYTES_IN_REG = 6;
93 uint8_t CMD_LEN = 4+7;
98 cmd = (uint8_t *)malloc(CMD_LEN*
sizeof(uint8_t));
99 for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++)
101 cmd[0] = 0x80 + current_ic;
110 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
112 cmd[cmd_index] = config[current_ic][current_byte];
113 cmd_index = cmd_index + 1;
116 cfg_pec =
pec8_calc(BYTES_IN_REG, &config[current_ic][0]);
117 cmd[cmd_index ] = (uint8_t)cfg_pec;
118 cmd_index = cmd_index + 1;
131 uint8_t r_config[][7]
134 uint8_t BYTES_IN_REG = 7;
138 int8_t pec_error = 0;
140 uint8_t received_pec;
142 rx_data = (uint8_t *) malloc((BYTES_IN_REG*total_ic)*
sizeof(uint8_t));
146 for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++)
151 cmd[0] = 0x80 + current_ic;
162 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
164 r_config[current_ic][current_byte] = rx_data[current_byte];
167 received_pec = r_config[current_ic][6];
168 data_pec =
pec8_calc(6, &r_config[current_ic][0]);
169 if (received_pec != data_pec)
204 int data_counter = 0;
206 uint8_t data_pec = 0;
207 uint8_t received_pec = 0;
210 rx_data = (uint8_t *) malloc((7)*
sizeof(uint8_t));
211 for (
int i=0;
i<total_ic;
i++)
221 received_pec = rx_data[5];
223 if (received_pec != data_pec)
228 int cell_counter = 0;
232 temp = rx_data[data_counter++];
233 temp2 = (rx_data[data_counter]& 0x0F)<<8;
234 temp_codes[
i][0] = temp + temp2 -512;
235 temp2 = (rx_data[data_counter++])>>4;
236 temp = (rx_data[data_counter++])<<4;
237 temp_codes[
i][1] = temp+temp2 -512;
238 temp2 = (rx_data[data_counter++]);
239 temp = (rx_data[data_counter++]& 0x0F)<<8;
240 temp_codes[
i][2] = temp+temp2 -512;
253 uint8_t data_pec = 0;
254 uint8_t received_pec = 0;
257 rx_data = (uint8_t *) malloc((19)*
sizeof(uint8_t));
259 for (
int i=0;
i<total_ic;
i++)
269 received_pec = rx_data[18];
271 if (received_pec != data_pec)
276 int cell_counter = 0;
280 for (
int k = 0; k<12; k=k+2)
282 temp = rx_data[data_counter++];
283 temp2 = (uint16_t)(rx_data[data_counter]&0x0F)<<8;
284 cell_codes[
i][k] = temp + temp2 -512;
285 temp2 = (rx_data[data_counter++])>>4;
286 temp = (rx_data[data_counter++])<<4;
287 cell_codes[
i][k+1] = temp+temp2 -512;
300 uint8_t remainder = 0x41;
306 for (
int byte = 0; byte < len; ++byte)
311 remainder ^= data[byte];
316 for (uint8_t bit = 8; bit > 0; --bit)
323 remainder = (remainder << 1) ^
PEC_POLY;
327 remainder = (remainder << 1);
345 for (uint8_t
i = 0;
i < len;
i++)
359 for (uint8_t
i = 0;
i < tx_len;
i++)
365 for (uint8_t
i = 0;
i < rx_len;
i++)
uint8_t pec8_calc(uint8_t len, uint8_t *data)
Function that calculates PEC byte.
void LTC6803_sttmpad()
Function that Temp channel voltage measurement.
LTC6803-2 Multicell Battery Monitor.
#define output_high(pin)
Set "pin" high.
Header File for Linduino Libraries and Demo Code.
void LTC6803_wrcfg(uint8_t total_ic, uint8_t config[][6])
Function that writes configuration of LTC6803-1/-3.
void LTC6803_stcvad()
Function that starts Cell Voltage measurement.
void spi_write(int8_t data)
Write a data byte using the SPI hardware.
void spi_enable(uint8_t spi_clock_divider)
Setup the processor for hardware SPI communication.
union LT_union_int32_4bytes data
static uint16_t temp_codes[TOTAL_IC][3]
The Temp codes will be stored in the temp_codes[][3] array in the following format: ...
void spi_write_array(uint8_t len, uint8_t data[])
Writes an array of bytes out of the SPI port.
#define output_low(pin)
Set "pin" low.
void LTC6803_initialize()
Initializes 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.
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.
static uint16_t cell_codes[TOTAL_IC][12]
The cell codes will be stored in the cell_codes[][12] array in the following format: ...
uint8_t LTC6803_rdcv(uint8_t total_ic, uint16_t cell_codes[][12])
Function that reads Cell Voltage registers.
int8_t LTC6803_rdtmp(uint8_t total_ic, uint16_t temp_codes[][3])
Function that reads Temp Voltage registers.
int8_t LTC6803_rdcfg(uint8_t total_ic, uint8_t r_config[][7])
Function that reads configuration of LTC6803-2/-3.