92 uint8_t BYTES_IN_REG = 6;
93 uint8_t CMD_LEN = 2+(7*total_ic);
98 cmd = (uint8_t *)malloc(CMD_LEN*
sizeof(uint8_t));
104 for (uint8_t current_ic = total_ic; current_ic > 0; current_ic--)
107 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
109 cmd[cmd_index] = config[current_ic-1][current_byte];
110 cmd_index = cmd_index + 1;
113 cfg_pec =
pec8_calc(BYTES_IN_REG, &config[current_ic-1][0]);
114 cmd[cmd_index ] = (uint8_t)cfg_pec;
115 cmd_index = cmd_index + 1;
127 uint8_t r_config[][7]
130 uint8_t BYTES_IN_REG = 7;
134 int8_t pec_error = 0;
136 uint8_t received_pec;
138 rx_data = (uint8_t *) malloc((BYTES_IN_REG*total_ic)*
sizeof(uint8_t));
149 for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++)
154 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
156 r_config[current_ic][current_byte] = rx_data[current_byte + (current_ic*BYTES_IN_REG)];
159 received_pec = r_config[current_ic][6];
160 data_pec =
pec8_calc(6, &r_config[current_ic][0]);
161 if (received_pec != data_pec)
197 int data_counter = 0;
199 uint8_t data_pec = 0;
200 uint8_t received_pec = 0;
202 rx_data = (uint8_t *) malloc((6*total_ic)*
sizeof(uint8_t));
207 for (
int i=0;
i<total_ic;
i++)
209 for (
int j = 0; j<6 ; j++)
211 rx_data[data_counter++] =
spi_read(0xFF);
216 int cell_counter = 0;
220 for (
int j =0; j<total_ic; j++)
222 received_pec = rx_data[5 +(6*j)];
223 data_pec =
pec8_calc(5, &rx_data[(6*j)]);
224 if (received_pec != data_pec)
229 temp = rx_data[data_counter++];
230 temp2 = (rx_data[data_counter]& 0x0F)<<8;
231 temp_codes[j][0] = temp + temp2 -512;
232 temp2 = (rx_data[data_counter++])>>4;
233 temp = (rx_data[data_counter++])<<4;
234 temp_codes[j][1] = temp+temp2 -512;
235 temp2 = (rx_data[data_counter++]);
236 temp = (rx_data[data_counter++]& 0x0F)<<8;
237 temp_codes[j][2] = temp+temp2 -512;
250 uint8_t data_pec = 0;
251 uint8_t received_pec = 0;
253 rx_data = (uint8_t *) malloc((19*total_ic)*
sizeof(uint8_t));
258 for (
int i=0;
i<total_ic;
i++)
260 for (
int j = 0; j<19 ; j++)
262 rx_data[data_counter++] =
spi_read(0xFF);
267 int cell_counter = 0;
272 for (
int j =0; j<total_ic; j++)
275 received_pec = rx_data[18 +(19*j)];
276 data_pec =
pec8_calc(18, &rx_data[(19*j)]);
277 if (received_pec != data_pec)
282 for (
int k = 0; k<12; k=k+2)
285 temp = rx_data[data_counter++];
287 temp2 = (uint16_t)(rx_data[data_counter]&0x0F)<<8;
289 cell_codes[j][k] = temp + temp2 -512;
290 temp2 = (rx_data[data_counter++])>>4;
292 temp = (rx_data[data_counter++])<<4;
294 cell_codes[j][k+1] = temp+temp2 -512;
308 uint8_t remainder = 0x41;
314 for (
int byte = 0; byte < len; ++byte)
319 remainder ^= data[byte];
324 for (uint8_t bit = 8; bit > 0; --bit)
331 remainder = (remainder << 1) ^
PEC_POLY;
335 remainder = (remainder << 1);
353 for (uint8_t
i = 0;
i < len;
i++)
367 for (uint8_t
i = 0;
i < tx_len;
i++)
373 for (uint8_t
i = 0;
i < rx_len;
i++)
void spi_write_array(uint8_t len, uint8_t data[])
void spi_write_read(uint8_t tx_Data[], uint8_t tx_len, uint8_t *rx_data, uint8_t rx_len)
#define output_high(pin)
Set "pin" high.
Header File for Linduino Libraries and Demo Code.
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: ...
LTC6803-1 Multicell Battery Monitor.
#define output_low(pin)
Set "pin" low.
uint8_t pec8_calc(uint8_t len, uint8_t *data)
Function that calculates PEC byte.
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...
void LTC6803_sttmpad()
Function to start Temp channel voltage measurement.
int8_t spi_read(int8_t data)
The data byte to be written.
void LTC6803_wrcfg(uint8_t total_ic, uint8_t config[][6])
Function that writes configuration of LTC6803-1/-3.
int8_t LTC6803_rdtmp(uint8_t total_ic, uint16_t temp_codes[][3])
Function that reads Temp Voltage registers.
void LTC6803_initialize()
Initializes the SPI port.
uint8_t LTC6803_rdcv(uint8_t total_ic, uint16_t cell_codes[][12])
Function that reads Cell Voltage registers.
static uint16_t cell_codes[TOTAL_IC][12]
The cell codes will be stored in the cell_codes[][12] array in the following format: ...
int8_t LTC6803_rdcfg(uint8_t total_ic, uint8_t r_config[][7])
Function that reads configuration of LTC6803-1/-3.
void LTC6803_stcvad()
Function to start Cell Voltage measurement.