56 for (
int i =0;
i<total_ic;
i++)
67 for (
int i =0;
i<total_ic;
i++)
86 cmd[2] = (uint8_t)(cmd_pec >> 8);
87 cmd[3] = (uint8_t)(cmd_pec);
103 const uint8_t BYTES_IN_REG = 6;
104 const uint8_t CMD_LEN = 4+(8*total_ic);
110 cmd = (uint8_t *)malloc(CMD_LEN*
sizeof(uint8_t));
114 cmd[2] = (uint8_t)(cmd_pec >> 8);
115 cmd[3] = (uint8_t)(cmd_pec);
118 for (uint8_t current_ic = total_ic; current_ic > 0; current_ic--)
120 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
122 cmd[cmd_index] = data[((current_ic-1)*6)+current_byte];
123 cmd_index = cmd_index + 1;
126 data_pec = (uint16_t)
pec15_calc(BYTES_IN_REG, &data[(current_ic-1)*6]);
127 cmd[cmd_index] = (uint8_t)(data_pec >> 8);
128 cmd[cmd_index + 1] = (uint8_t)data_pec;
129 cmd_index = cmd_index + 2;
145 const uint8_t BYTES_IN_REG = 8;
148 int8_t pec_error = 0;
151 uint16_t received_pec;
156 cmd[2] = (uint8_t)(cmd_pec >> 8);
157 cmd[3] = (uint8_t)(cmd_pec);
163 for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++)
165 for (uint8_t current_byte = 0; current_byte < BYTES_IN_REG; current_byte++)
167 rx_data[(current_ic*8)+current_byte] = data[current_byte + (current_ic*BYTES_IN_REG)];
170 received_pec = (rx_data[(current_ic*8)+6]<<8) + rx_data[(current_ic*8)+7];
171 data_pec =
pec15_calc(6, &rx_data[current_ic*8]);
173 if (received_pec != data_pec)
187 uint16_t remainder,addr;
190 for (uint8_t
i = 0;
i<len;
i++)
192 addr = ((remainder>>7)^data[
i])&0xff;
196 remainder = (remainder<<8)^pgm_read_word_near(
crc15Table+addr);
208 uint8_t cmd[2] = {0x00 , 0x01} ;
209 uint8_t write_buffer[256];
210 uint8_t write_count = 0;
213 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
221 c_ic = total_ic - current_ic - 1;
230 write_68(total_ic, cmd, write_buffer);
238 uint8_t cmd[2] = {0x00 , 0x24} ;
239 uint8_t write_buffer[256];
240 uint8_t write_count = 0;
243 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
251 c_ic = total_ic - current_ic - 1;
260 write_68(total_ic, cmd, write_buffer);
268 uint8_t cmd[2]= {0x00 , 0x02};
269 uint8_t read_buffer[256];
270 int8_t pec_error = 0;
275 pec_error =
read_68(total_ic, cmd, read_buffer);
277 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
285 c_ic = total_ic - current_ic - 1;
288 for (
int byte=0; byte<8; byte++)
290 ic[c_ic].
config.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
293 calc_pec =
pec15_calc(6,&read_buffer[8*current_ic]);
294 data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
295 if (calc_pec != data_pec )
311 uint8_t cmd[2]= {0x00 , 0x26};
312 uint8_t read_buffer[256];
313 int8_t pec_error = 0;
318 pec_error =
read_68(total_ic, cmd, read_buffer);
320 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
328 c_ic = total_ic - current_ic - 1;
331 for (
int byte=0; byte<8; byte++)
333 ic[c_ic].
configb.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
336 calc_pec =
pec15_calc(6,&read_buffer[8*current_ic]);
337 data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
338 if (calc_pec != data_pec )
358 md_bits = (MD & 0x02) >> 1;
359 cmd[0] = md_bits + 0x02;
360 md_bits = (MD & 0x01) << 7;
361 cmd[1] = md_bits + 0x60 + (DCP<<4) + CH;
374 md_bits = (MD & 0x02) >> 1;
375 cmd[0] = md_bits + 0x04;
376 md_bits = (MD & 0x01) << 7;
377 cmd[1] = md_bits + 0x60 + CHG ;
390 md_bits = (MD & 0x02) >> 1;
391 cmd[0] = md_bits + 0x04;
392 md_bits = (MD & 0x01) << 7;
393 cmd[1] = md_bits + 0x68 + CHST ;
406 md_bits = (MD & 0x02) >> 1;
407 cmd[0] = md_bits | 0x04;
408 md_bits = (MD & 0x01) << 7;
409 cmd[1] = md_bits | 0x60 | (DCP<<4) | 0x07;
422 md_bits = (MD & 0x02) >> 1;
423 cmd[0] = md_bits | 0x04;
424 md_bits = (MD & 0x01) << 7;
425 cmd[1] = md_bits | ((DCP&0x01)<<4) + 0x6F;
441 int8_t pec_error = 0;
444 cell_data = (uint8_t *) malloc((
NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
451 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
459 c_ic = total_ic - current_ic - 1;
461 pec_error = pec_error +
parse_cells(current_ic,cell_reg, cell_data,
462 &ic[c_ic].cells.c_codes[0],
472 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
480 c_ic = total_ic - current_ic - 1;
482 pec_error = pec_error +
parse_cells(current_ic,reg, &cell_data[8*c_ic],
483 &ic[c_ic].cells.c_codes[0],
504 int8_t pec_error = 0;
506 data = (uint8_t *) malloc((
NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
513 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
521 c_ic = total_ic - current_ic - 1;
524 &ic[c_ic].aux.a_codes[0],
533 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
541 c_ic = total_ic - current_ic - 1;
544 &ic[c_ic].aux.a_codes[0],
566 const uint8_t BYT_IN_REG = 6;
567 const uint8_t STAT_IN_REG = 3;
569 uint8_t data_counter = 0;
570 int8_t pec_error = 0;
571 uint16_t parsed_stat;
572 uint16_t received_pec;
576 data = (uint8_t *) malloc((12*total_ic)*
sizeof(uint8_t));
580 for (uint8_t stat_reg = 1; stat_reg< 3; stat_reg++)
585 for (uint8_t current_ic = 0 ; current_ic < total_ic; current_ic++)
593 c_ic = total_ic - current_ic - 1;
598 for (uint8_t current_stat = 0; current_stat< STAT_IN_REG; current_stat++)
600 parsed_stat = data[data_counter] + (data[data_counter+1]<<8);
602 data_counter=data_counter+2;
605 else if (stat_reg == 2)
607 parsed_stat = data[data_counter] + (data[data_counter+1]<<8);
608 data_counter = data_counter +2;
610 ic[c_ic].
stat.
flags[0] = data[data_counter++];
611 ic[c_ic].
stat.
flags[1] = data[data_counter++];
612 ic[c_ic].
stat.
flags[2] = data[data_counter++];
613 ic[c_ic].
stat.
mux_fail[0] = (data[data_counter] & 0x02)>>1;
614 ic[c_ic].
stat.
thsd[0] = data[data_counter++] & 0x01;
617 received_pec = (data[data_counter]<<8)+ data[data_counter+1];
621 if (received_pec != data_pec)
632 data_counter=data_counter+2;
640 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
648 c_ic = total_ic - current_ic - 1;
652 for (uint8_t current_stat = 0; current_stat< STAT_IN_REG; current_stat++)
655 parsed_stat = data[data_counter] + (data[data_counter+1]<<8);
659 data_counter=data_counter+2;
665 parsed_stat = data[data_counter++] + (data[data_counter++]<<8);
667 ic[c_ic].
stat.
flags[0] = data[data_counter++];
668 ic[c_ic].
stat.
flags[1] = data[data_counter++];
669 ic[c_ic].
stat.
flags[2] = data[data_counter++];
670 ic[c_ic].
stat.
mux_fail[0] = (data[data_counter] & 0x02)>>1;
671 ic[c_ic].
stat.
thsd[0] = data[data_counter++] & 0x01;
674 received_pec = (data[data_counter]<<8)+ data[data_counter+1];
677 if (received_pec != data_pec)
683 data_counter=data_counter+2;
699 const uint8_t REG_LEN = 8;
735 cmd[2] = (uint8_t)(cmd_pec >> 8);
736 cmd[3] = (uint8_t)(cmd_pec);
753 const uint8_t REG_LEN = 8;
784 cmd[2] = (uint8_t)(cmd_pec >> 8);
785 cmd[3] = (uint8_t)(cmd_pec);
802 const uint8_t REG_LEN = 8;
824 cmd[2] = (uint8_t)(cmd_pec >> 8);
825 cmd[3] = (uint8_t)(cmd_pec);
840 const uint8_t BYT_IN_REG = 6;
841 const uint8_t CELL_IN_REG = 3;
842 int8_t pec_error = 0;
843 uint16_t parsed_cell;
844 uint16_t received_pec;
849 for (uint8_t current_cell = 0; current_cell<CELL_IN_REG; current_cell++)
852 parsed_cell = cell_data[data_counter] + (cell_data[data_counter + 1] << 8);
854 cell_codes[current_cell + ((cell_reg - 1) * CELL_IN_REG)] = parsed_cell;
856 data_counter = data_counter + 2;
859 received_pec = (cell_data[data_counter] << 8) | cell_data[data_counter+1];
861 data_pec =
pec15_calc(BYT_IN_REG, &cell_data[(current_ic) * NUM_RX_BYT]);
863 if (received_pec != data_pec)
866 ic_pec[cell_reg-1]=1;
870 ic_pec[cell_reg-1]=0;
872 data_counter=data_counter+2;
881 uint8_t adc_state = 0xFF;
887 cmd[2] = (uint8_t)(cmd_pec >> 8);
888 cmd[3] = (uint8_t)(cmd_pec);
901 uint32_t counter = 0;
902 uint8_t finished = 0;
903 uint8_t current_time = 0;
910 cmd[2] = (uint8_t)(cmd_pec >> 8);
911 cmd[3] = (uint8_t)(cmd_pec);
915 while ((counter<200000)&&(finished == 0))
924 counter = counter + 10;
939 uint8_t cmd[2]= {0x07 , 0x11};
950 uint8_t cmd[2]= {0x07 , 0x12};
962 uint8_t cmd[2]= {0x07 , 0x13};
969 uint8_t cmd[2] = {0x07 , 0x15};
981 md_bits = (MD & 0x02) >> 1;
982 cmd[0] = md_bits + 0x02;
983 md_bits = (MD & 0x01) << 7;
984 cmd[1] = md_bits + ((ST)<<5) +0x07;
997 md_bits = (MD & 0x02) >> 1;
998 cmd[0] = md_bits + 0x04;
999 md_bits = (MD & 0x01) << 7;
1000 cmd[1] = md_bits + ((ST&0x03)<<5) +0x07;
1013 md_bits = (MD & 0x02) >> 1;
1014 cmd[0] = md_bits + 0x04;
1015 md_bits = (MD & 0x01) << 7;
1016 cmd[1] = md_bits + ((ST&0x03)<<5) +0x0F;
1029 md_bits = (MD & 0x02) >> 1;
1030 cmd[0] = md_bits + 0x02;
1031 md_bits = (MD & 0x01) << 7;
1032 cmd[1] = md_bits + (DCP<<4) +0x01;
1045 md_bits = (MD & 0x02) >> 1;
1046 cmd[0] = md_bits + 0x04;
1047 md_bits = (MD & 0x01) << 7;
1048 cmd[1] = md_bits + CHG ;
1061 md_bits = (MD & 0x02) >> 1;
1062 cmd[0] = md_bits + 0x04;
1063 md_bits = (MD & 0x01) << 7;
1064 cmd[1] = md_bits + 0x08 + CHST ;
1078 uint16_t expected_result = 0;
1080 for (
int self_test = 1; self_test<3; self_test++)
1095 for (
int cic = 0; cic < total_ic; cic++)
1100 if (ic[cic].cells.c_codes[
channel] != expected_result)
1116 for (
int cic = 0; cic < total_ic; cic++)
1121 if (ic[cic].aux.a_codes[
channel] != expected_result)
1136 for (
int cic = 0; cic < total_ic; cic++)
1140 if (ic[cic].stat.stat_codes[
channel] != expected_result)
1163 int32_t measure_delta =0;
1164 int16_t failure_pos_limit = 20;
1165 int16_t failure_neg_limit = -20;
1174 for (
int cic = 0; cic<total_ic; cic++)
1176 measure_delta = (int32_t)ic[cic].cells.c_codes[6]-(int32_t)ic[cic].
cells.
c_codes[7];
1178 if ((measure_delta>failure_pos_limit) || (measure_delta<failure_neg_limit))
1180 error = error | (1<<(cic-1));
1195 for (
int self_test = 1; self_test<3; self_test++)
1207 for (
int cic = 0; cic < total_ic; cic++)
1211 if (ic[cic].aux.a_codes[
channel] >= 65280)
1224 for (
int cic = 0; cic < total_ic; cic++)
1228 if (ic[cic].stat.stat_codes[
channel] >= 65280)
1250 uint16_t test_pattern = 0;
1254 if ( adcopt ==
false)
1258 test_pattern = 0x9565;
1262 test_pattern = 0x6A9A;
1269 test_pattern = 0x9553;
1273 test_pattern = 0x6AAC;
1281 test_pattern = 0x9555;
1285 test_pattern = 0x6AAA;
1288 return(test_pattern);
1301 md_bits = (MD & 0x02) >> 1;
1302 cmd[0] = md_bits + 0x02;
1303 md_bits = (MD & 0x01) << 7;
1304 cmd[1] = md_bits + 0x28 + (PUP<<6) + CH+(DCP<<4);
1317 md_bits = (MD & 0x02) >> 1;
1318 cmd[0] = md_bits + 0x04;
1319 md_bits = (MD & 0x01) << 7;
1320 cmd[1] = md_bits + 0x10+ (PUP<<6) ;
1330 uint16_t OPENWIRE_THRESHOLD = 4000;
1333 uint16_t pullUp[total_ic][N_CHANNELS];
1334 uint16_t pullDwn[total_ic][N_CHANNELS];
1335 int16_t openWire_delta[total_ic][N_CHANNELS];
1339 uint32_t conv_time=0;
1345 for (i = 0; i < 3; i++)
1355 for (
int cic=0; cic<total_ic; cic++)
1357 for (
int cell=0; cell<N_CHANNELS; cell++)
1364 for (i = 0; i < 3; i++)
1374 for (
int cic=0; cic<total_ic; cic++)
1376 for (
int cell=0; cell<N_CHANNELS; cell++)
1382 for (
int cic=0; cic<total_ic; cic++)
1386 for (
int cell=0; cell<N_CHANNELS; cell++)
1388 if (pullDwn[cic][cell] < pullUp[cic][cell])
1390 openWire_delta[cic][cell] = (pullUp[cic][cell] - pullDwn[cic][cell]);
1394 openWire_delta[cic][cell] = 0;
1397 if (openWire_delta[cic][cell]>OPENWIRE_THRESHOLD)
1403 if (pullUp[cic][0] == 0)
1408 if (pullUp[cic][(N_CHANNELS-1)] == 0)
1420 uint16_t OPENWIRE_THRESHOLD = 4000;
1423 uint16_t pullUp[total_ic][N_CHANNELS];
1424 uint16_t pullDwn[total_ic][N_CHANNELS];
1425 uint16_t openWire_delta[total_ic][N_CHANNELS];
1428 int8_t opencells[N_CHANNELS];
1431 uint32_t conv_time=0;
1437 for (i = 0; i < 5; i++)
1447 for (
int cic=0; cic<total_ic; cic++)
1449 for (
int cell=0; cell<N_CHANNELS; cell++)
1456 for (i = 0; i < 5; i++)
1466 for (
int cic=0; cic<total_ic; cic++)
1468 for (
int cell=0; cell<N_CHANNELS; cell++)
1474 for (
int cic=0; cic<total_ic; cic++)
1476 for (
int cell=0; cell<N_CHANNELS; cell++)
1478 if (pullDwn[cic][cell] < pullUp[cic][cell])
1480 openWire_delta[cic][cell] = (pullUp[cic][cell] - pullDwn[cic][cell]);
1484 openWire_delta[cic][cell] = 0;
1489 for (
int cic=0; cic<total_ic; cic++)
1493 Serial.print(
"IC:");
1494 Serial.println(cic+1, DEC);
1496 for (
int cell=0; cell<N_CHANNELS; cell++)
1499 if (openWire_delta[cic][cell]>OPENWIRE_THRESHOLD)
1501 opencells[n] = cell+1;
1503 for (
int j = cell; j < N_CHANNELS-3 ; j++)
1505 if (pullUp[cic][j + 2] == 0)
1511 if((cell==N_CHANNELS-4) && (pullDwn[cic][N_CHANNELS-3] == 0))
1513 opencells[n] = N_CHANNELS-2;
1518 if (pullDwn[cic][0] == 0)
1521 Serial.println(
"Cell 0 is Open and multiple open wires maybe possible.");
1525 if (pullDwn[cic][N_CHANNELS-1] == 0)
1527 opencells[n] = N_CHANNELS;
1531 if (pullDwn[cic][N_CHANNELS-2] == 0)
1533 opencells[n] = N_CHANNELS-1;
1542 if(opencells[i]==opencells[j])
1545 opencells[k]=opencells[k+1];
1555 for(
int i=0; i<n; i++)
1557 for(
int j=0; j<n-1; j++)
1559 if( opencells[j] > opencells[j+1] )
1562 opencells[j] = opencells[j+1];
1569 Serial.println(
"Number of Open wires:");
1573 Serial.println(
"OPEN CELLS:");
1576 Serial.println(
"No Open wires");
1582 Serial.println(opencells[i]);
1586 Serial.println(
"\n");
1594 uint16_t OPENWIRE_THRESHOLD = 150;
1597 uint16_t aux_val[total_ic][N_CHANNELS];
1598 uint16_t pDwn[total_ic][N_CHANNELS];
1599 uint16_t ow_delta[total_ic][N_CHANNELS];
1603 uint32_t conv_time=0;
1608 for (i = 0; i < 3; i++)
1618 for (
int cic=0; cic<total_ic; cic++)
1628 for (i = 0; i < 3; i++)
1638 for (
int cic=0; cic<total_ic; cic++)
1646 for (
int cic=0; cic<total_ic; cic++)
1663 if (ow_delta[cic][channel] > OPENWIRE_THRESHOLD)
1671 if (ow_delta[cic][channel] > OPENWIRE_THRESHOLD)
1686 for (
int i=0;
i<total_ic;
i++)
1702 uint8_t write_buffer[256];
1703 uint8_t write_count = 0;
1716 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
1724 c_ic = total_ic - current_ic - 1;
1733 write_68(total_ic, cmd, write_buffer);
1743 const uint8_t BYTES_IN_REG = 8;
1745 uint8_t read_buffer[256];
1746 int8_t pec_error = 0;
1762 pec_error =
read_68(total_ic, cmd, read_buffer);
1763 for (uint8_t current_ic =0; current_ic<total_ic; current_ic++)
1771 c_ic = total_ic - current_ic - 1;
1774 for (
int byte=0; byte<8; byte++)
1776 ic[c_ic].
pwm.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
1779 calc_pec =
pec15_calc(6,&read_buffer[8*current_ic]);
1780 data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
1781 if (calc_pec != data_pec )
1797 uint8_t write_buffer[256];
1798 uint8_t write_count = 0;
1811 for(uint8_t current_ic = 0; current_ic<total_ic;current_ic++)
1814 else{c_ic = total_ic - current_ic - 1;}
1823 write_68(total_ic, cmd, write_buffer);
1833 uint8_t read_buffer[256];
1834 int8_t pec_error = 0;
1850 pec_error =
read_68(total_ic, cmd, read_buffer);
1852 for(uint8_t current_ic =0; current_ic<total_ic; current_ic++)
1855 else{c_ic = total_ic - current_ic - 1;}
1858 for(
int byte=0; byte<8;byte++)
1860 ic[c_ic].
sctrl.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
1863 calc_pec =
pec15_calc(6,&read_buffer[8*current_ic]);
1864 data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
1865 if(calc_pec != data_pec )
1887 cmd[2] = (uint8_t)(cmd_pec >> 8);
1888 cmd[3] = (uint8_t)(cmd_pec);
1902 uint8_t cmd[2]= {0x00 , 0x18};
1911 uint8_t cmd[2]= {0x07 , 0x21};
1912 uint8_t write_buffer[256];
1913 uint8_t write_count = 0;
1915 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
1923 c_ic = total_ic - current_ic - 1;
1932 write_68(total_ic, cmd, write_buffer);
1940 uint8_t cmd[2]= {0x07 , 0x22};
1941 uint8_t read_buffer[256];
1942 int8_t pec_error = 0;
1947 pec_error =
read_68(total_ic, cmd, read_buffer);
1949 for (uint8_t current_ic = 0; current_ic<total_ic; current_ic++)
1957 c_ic = total_ic - current_ic - 1;
1960 for (
int byte=0; byte<8; byte++)
1962 ic[c_ic].
com.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
1965 calc_pec =
pec15_calc(6,&read_buffer[8*current_ic]);
1966 data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
1967 if (calc_pec != data_pec )
1986 cmd[2] = (uint8_t)(cmd_pec >> 8);
1987 cmd[3] = (uint8_t)(cmd_pec);
1991 for (
int i = 0;
i<len*3;
i++)
2007 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
2015 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
2022 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
2032 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
2043 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
2063 for (
int current_ic = 0 ; current_ic < total_ic; current_ic++)
2067 for (
int i=0;
i<6;
i++)
2072 for (
int i=0;
i<4;
i++)
2076 for (
int i=0;
i<2;
i++)
2088 for (uint8_t current_ic = 0; current_ic<total_ic;current_ic++)
2090 for (
int j =0; j<6; j++)
2135 for (
int i =0;
i<5;
i++)
2145 for (
int i =0;
i<8;
i++)
2150 for (
int i =0;
i<4;
i++)
2160 for(
int i =0;
i<4;
i++)
2170 uint16_t tmp = (uv/16)-1;
2179 uint16_t tmp = (ov/16);
void LTC681x_rdcv_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Reads the raw cell voltage register data.
void LTC681x_adaxd(uint8_t MD, uint8_t CHG)
Start an GPIO Redundancy test.
void LTC681x_adcvax(uint8_t MD, uint8_t DCP)
Starts cell voltage and GPIO 1&2 conversion.
uint16_t stat_pec[2]
Status register data PEC error count.
void spi_write_array(uint8_t len, uint8_t data[])
uint16_t a_codes[9]
Aux Voltage Codes.
void LTC681x_stcomm(uint8_t len)
Issues a stcomm command and clocks data out of the COMM register.
void LTC681x_adow(uint8_t MD, uint8_t PUP, uint8_t CH, uint8_t DCP)
Start an open wire Conversion.
void LTC681x_set_cfgr_gpio(uint8_t nIC, cell_asic *ic, bool gpio[5])
uint8_t spi_read_byte(uint8_t tx_dat)
void spi_write_read(uint8_t tx_Data[], uint8_t tx_len, uint8_t *rx_data, uint8_t rx_len)
void LTC681x_diagn()
Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnosti...
uint8_t pec_match[4]
If a PEC error was detected during most recent read cmd.
int8_t LTC681x_rdstat(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x stat registers.
uint8_t tx_data[6]
Stores data to be transmitted.
#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 ...
uint16_t stat_codes[4]
Status codes.
void LTC681x_wrpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic ic[])
void LTC681x_set_cfgr(uint8_t nIC, cell_asic *ic, bool refon, bool adcopt, bool gpio[5], bool dcc[12], bool dcto[4], uint16_t uv, uint16_t ov)
Helper function to set appropriate bits in CFGR register based on bit function.
uint8_t mux_fail[1]
Mux self test status flag.
void LTC681x_set_cfgr_uv(uint8_t nIC, cell_asic *ic, uint16_t uv)
Helper function to set uv field in CFGRA register.
uint16_t LTC681x_run_adc_overlap(uint8_t total_ic, cell_asic *ic)
Helper Function that runs the ADC Overlap test.
uint8_t rx_data[8]
Stores received data.
void LTC681x_axow(uint8_t MD, uint8_t PUP)
Start GPIOs open wire ADC conversion.
void LTC681x_clrcell()
Clears the LTC681x Cell voltage registers The command clears the cell voltage registers and initializ...
void LTC681x_statst(uint8_t MD, uint8_t ST)
Start a Status Register Self Test Conversion.
int8_t LTC681x_rdcfgb(uint8_t total_ic, cell_asic ic[])
void LTC681x_adstat(uint8_t MD, uint8_t CHST)
Start a Status ADC Conversion.
void wakeup_sleep(uint8_t total_ic)
Wake the LTC681x from the sleep state.
#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 LTC681x_clrsctrl()
Clears the LTC681x SCTRL registers The command clears the SCTRL registers and initializes all values ...
static uint8_t channel
LTC2305 Channel selection.
void LTC681x_wrcfg(uint8_t total_ic, cell_asic ic[])
void LTC681x_set_cfgr_ov(uint8_t nIC, cell_asic *ic, uint16_t ov)
Helper function to set ov field in CFGRA register.
uint8_t num_cv_reg
Number of Cell voltage register.
uint8_t num_gpio_reg
Number of Aux register.
void LTC681x_wrsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Write the LTC681x Sctrl register.
void LTC681x_adax(uint8_t MD, uint8_t CHG)
Start a GPIO and Vref2 Conversion.
void cs_low(uint8_t pin)
ltc681x hardware library
void LTC681x_set_cfgr_refon(uint8_t nIC, cell_asic *ic, bool refon)
Helper function to turn the REFON bit HIGH or LOW.
void LTC681x_rdaux_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Read the raw data from the LTC681x auxiliary register The function reads a single GPIO voltage regist...
uint8_t LTC681x_rdcv(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x cell voltage registers.
#define PULL_DOWN_CURRENT
void LTC681x_run_gpio_openwire(uint8_t total_ic, cell_asic ic[])
void LTC681x_rdstat_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Read the raw data from the LTC681x stat register The function reads a single Status register and stor...
uint16_t cell_pec[6]
Cell voltage register data PEC error count.
void LTC681x_cvst(uint8_t MD, uint8_t ST)
Starts cell voltage self test conversion.
union LT_union_int32_4bytes data
void LTC681x_adcvsc(uint8_t MD, uint8_t DCP)
Starts cell voltage and SOC conversion.
void LTC681x_wrcomm(uint8_t total_ic, cell_asic ic[])
void LTC681x_stsctrl()
Start Sctrl data communication This command will start the sctrl pulse communication over the spins...
int8_t LTC681x_rdsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Reads sctrl registers of a LTC681x daisy chain.
void LTC681x_reset_crc_count(uint8_t total_ic, cell_asic *ic)
Helper Function that resets the PEC error counters.
void LTC681x_clear_discharge(uint8_t total_ic, cell_asic *ic)
Helper Function to clear DCC bits in the CFGR Registers.
static const unsigned int crc15Table[256]
void delay_u(uint16_t micro)
int8_t LTC681x_rdaux(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x auxiliary registers.
uint16_t pec_count
Overall PEC error count.
uint8_t stat_channels
Number of Stat channels.
void LTC681x_adstatd(uint8_t MD, uint8_t CHST)
Start a Status register redundancy test Conversion.
void LTC681x_clrstat()
Clears the LTC681x Stat registers The command clears the Stat registers and initializes all values to...
uint32_t LTC681x_pollAdc()
This function will block operation until the ADC has finished it's conversion.
void LTC681x_axst(uint8_t MD, uint8_t ST)
Start an Auxiliary Register Self Test Conversion.
void LTC681x_check_pec(uint8_t total_ic, uint8_t reg, cell_asic *ic)
Helper Function that counts overall PEC errors and register/IC PEC errors.
uint8_t LTC681x_pladc()
Sends the poll ADC command.
int8_t read_68(uint8_t total_ic, uint8_t tx_cmd[2], uint8_t *rx_data)
Issues a command onto the daisy chain and reads back 6*total_ic data in the rx_data array...
uint8_t cell_channels
Number of Cell channels.
uint8_t num_stat_reg
Number of Status register.
uint8_t thsd[1]
Thermal shutdown status.
uint8_t pec_match[2]
If a PEC error was detected during most recent read cmd.
uint8_t pec_match[6]
If a PEC error was detected during most recent read cmd.
void LTC681x_set_cfgr_dcto(uint8_t nIC, cell_asic *ic, bool dcto[4])
void cmd_68(uint8_t tx_cmd[2])
Sends a command to the BMS IC.
int8_t LTC681x_rdpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic ic[])
uint8_t rx_pec_match
If a PEC error was detected during most recent read cmd.
uint16_t cfgr_pec
Configuration register data PEC error count.
int8_t LTC681x_rdcomm(uint8_t total_ic, cell_asic ic[])
void cs_high(uint8_t pin)
uint16_t c_codes[18]
Cell Voltage Codes.
void LTC681x_init_cfg(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR data structures.
int8_t LTC681x_rdcfg(uint8_t total_ic, cell_asic ic[])
void LTC681x_clraux()
Clears the LTC681x Auxiliary registers The command clears the Auxiliary registers and initializes all...
void LTC681x_adcv(uint8_t MD, uint8_t DCP, uint8_t CH)
Starts cell voltage conversion Starts ADC conversions of the LTC681x Cpin inputs. ...
int16_t LTC681x_run_adc_redundancy_st(uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic *ic)
Helper function that runs the ADC Digital Redundancy commands and checks output for errors...
void LTC681x_set_cfgr_adcopt(uint8_t nIC, cell_asic *ic, bool adcopt)
Helper function to turn the ADCOPT bit HIGH or LOW.
void LTC681x_run_openwire_multi(uint8_t total_ic, cell_asic ic[])
void LTC681x_run_openwire_single(uint8_t total_ic, cell_asic ic[])
void LTC681x_set_cfgr_dis(uint8_t nIC, cell_asic *ic, bool dcc[12])
uint8_t aux_channels
Number of Aux channels.
void LTC681x_adol(uint8_t MD, uint8_t DCP)
Starts cell voltage overlap conversion.
int16_t LTC681x_run_cell_adc_st(uint8_t adc_reg, uint8_t total_ic, cell_asic *ic, uint8_t md, bool adcopt)
Helper function that runs the ADC Self Tests.
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 wakeup_idle(uint8_t total_ic)
Wake isoSPI up from IDlE state and enters the READY state.
int8_t parse_cells(uint8_t current_ic, uint8_t cell_reg, uint8_t cell_data[], uint16_t *cell_codes, uint8_t *ic_pec)
Helper function that parses voltage measurement registers.
uint16_t LTC681x_st_lookup(uint8_t MD, uint8_t ST, bool adcopt)
Self Test Helper Function.
void LTC681x_wrcfgb(uint8_t total_ic, cell_asic ic[])
uint16_t pec15_calc(uint8_t len, uint8_t *data)
uint16_t aux_pec[4]
Aux register data PEC error count.
void write_68(uint8_t total_ic, uint8_t tx_cmd[2], uint8_t data[])
Writes an array of data to the daisy chain.
uint8_t flags[3]
Byte array that contains the uv/ov flag data.