APS Lab
/
BMS_3029
LTC6811 Battery Management System with ADuCM3029.
Diff: LTC681x.cpp
- Revision:
- 1:4dd3e328a30b
- Parent:
- 0:f06ed53310a3
--- a/LTC681x.cpp Wed Feb 07 08:26:04 2018 +0000 +++ b/LTC681x.cpp Fri Feb 09 04:43:04 2018 +0000 @@ -13,10 +13,10 @@ void wakeup_idle(uint8_t total_ic) { for (int i =0; i<total_ic; i++) { - //spi2_CS = 0; -// wait_ms(2); //Guarantees the isoSPI will be in ready mode + cs_low(); + wait_ms(2); //Guarantees the isoSPI will be in ready mode spi_read_byte(0xff); - //spi2_CS = 1; + cs_high(); } } @@ -24,9 +24,9 @@ void wakeup_sleep(uint8_t total_ic) { for (int i =0; i<total_ic; i++) { - //spi2_CS = 0; + cs_low(); delay_u(300); // Guarantees the LTC6813 will be in standby - //spi2_CS = 1; + cs_high(); delay_u(10); } } @@ -43,9 +43,9 @@ cmd_pec = pec15_calc(2, cmd); cmd[2] = (uint8_t)(cmd_pec >> 8); cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_array(4,cmd); - //spi2_CS = 1; + cs_high(); } //Generic function to write 68xx commands and write payload data. Function calculated PEC for tx_cmd data @@ -81,9 +81,9 @@ } - //spi2_CS = 0; + cs_low(); spi_write_array(CMD_LEN, cmd); - //spi2_CS = 1; + cs_high(); free(cmd); } @@ -107,9 +107,9 @@ cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_read(cmd, 4, data, (BYTES_IN_REG*total_ic)); //Read the configuration data of all ICs on the daisy chain into - //spi2_CS = 1; //rx_data[] array + cs_high(); //rx_data[] array for (uint8_t current_ic = 0; current_ic < total_ic; current_ic++) { //executes for each LTC681x in the daisy chain and packs the data //into the r_comm array as well as check the received Config data @@ -279,10 +279,10 @@ cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_array(4,cmd); // adc_state = spi_read_byte(0xFF); - //spi2_CS = 1; + cs_high(); return(adc_state); } @@ -302,7 +302,7 @@ cmd[2] = (uint8_t)(cmd_pec >> 8); cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_array(4,cmd); while ((counter<200000)&&(finished == 0)) { @@ -313,8 +313,8 @@ counter = counter + 10; } } - //spi2_CS = 1; - + cs_high(); + return(counter); } @@ -436,9 +436,9 @@ cmd[2] = (uint8_t)(cmd_pec >> 8); cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_read(cmd,4,data,(REG_LEN*total_ic)); - //spi2_CS = 1; + cs_high(); } @@ -515,9 +515,9 @@ cmd[2] = (uint8_t)(cmd_pec >> 8); cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_read(cmd,4,data,(REG_LEN*total_ic)); - //spi2_CS = 1; + cs_high(); } @@ -553,9 +553,9 @@ cmd[2] = (uint8_t)(cmd_pec >> 8); cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_read(cmd,4,data,(REG_LEN*total_ic)); - //spi2_CS = 1; + cs_high(); } @@ -1381,12 +1381,12 @@ cmd[2] = (uint8_t)(cmd_pec >> 8); cmd[3] = (uint8_t)(cmd_pec); - //spi2_CS = 0; + cs_low(); spi_write_array(4,cmd); for (int i = 0; i<9; i++) { spi_read_byte(0xFF); } - //spi2_CS = 1; + cs_high(); }