BMS

Dependencies:   bms_master mbed

Committer:
roger5641
Date:
Tue Nov 21 05:54:34 2017 +0000
Revision:
5:4c6c92733561
Parent:
4:47d6a0b63e38
Child:
6:c2ab60b20d11
add fan and led digitalOut

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roger5641 2:e0ec3ed506ea 1 /*
roger5641 0:3547f7580dbd 2 Copyright (c) 2017, Linear Technology Corp.(LTC)
roger5641 0:3547f7580dbd 3 All rights reserved.
roger5641 0:3547f7580dbd 4
roger5641 0:3547f7580dbd 5 Redistribution and use in source and binary forms, with or without
roger5641 0:3547f7580dbd 6 modification, are permitted provided that the following conditions are met:
roger5641 0:3547f7580dbd 7
roger5641 0:3547f7580dbd 8 1. Redistributions of source code must retain the above copyright notice, this
roger5641 0:3547f7580dbd 9 list of conditions and the following disclaimer.
roger5641 0:3547f7580dbd 10 2. Redistributions in binary form must reproduce the above copyright notice,
roger5641 0:3547f7580dbd 11 this list of conditions and the following disclaimer in the documentation
roger5641 0:3547f7580dbd 12 and/or other materials provided with the distribution.
roger5641 0:3547f7580dbd 13
roger5641 0:3547f7580dbd 14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
roger5641 0:3547f7580dbd 15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
roger5641 0:3547f7580dbd 16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
roger5641 0:3547f7580dbd 17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
roger5641 0:3547f7580dbd 18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
roger5641 0:3547f7580dbd 19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
roger5641 0:3547f7580dbd 20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
roger5641 0:3547f7580dbd 21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
roger5641 0:3547f7580dbd 22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
roger5641 0:3547f7580dbd 23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
roger5641 0:3547f7580dbd 24
roger5641 0:3547f7580dbd 25 The views and conclusions contained in the software and documentation are those
roger5641 0:3547f7580dbd 26 of the authors and should not be interpreted as representing official policies,
roger5641 0:3547f7580dbd 27 either expressed or implied, of Linear Technology Corp.
roger5641 0:3547f7580dbd 28
roger5641 0:3547f7580dbd 29 The Linear Technology Linduino is not affiliated with the official Arduino team.
roger5641 0:3547f7580dbd 30 However, the Linduino is only possible because of the Arduino team's commitment
roger5641 0:3547f7580dbd 31 to the open-source community. Please, visit http://www.arduino.cc and
roger5641 0:3547f7580dbd 32 http://store.arduino.cc , and consider a purchase that will help fund their
roger5641 0:3547f7580dbd 33 ongoing work.
roger5641 0:3547f7580dbd 34
roger5641 0:3547f7580dbd 35 Copyright 2017 Linear Technology Corp. (LTC)
roger5641 0:3547f7580dbd 36 */
roger5641 0:3547f7580dbd 37
roger5641 0:3547f7580dbd 38 #include "mbed.h"
roger5641 0:3547f7580dbd 39 #include <stdint.h>
roger5641 2:e0ec3ed506ea 40 #include "bms_master.h"
roger5641 0:3547f7580dbd 41
roger5641 0:3547f7580dbd 42 #define ENABLED 1
roger5641 0:3547f7580dbd 43 #define DISABLED 0
roger5641 0:3547f7580dbd 44
roger5641 0:3547f7580dbd 45 #define DATALOG_ENABLED 1
roger5641 0:3547f7580dbd 46 #define DATALOG_DISABLED 0
roger5641 0:3547f7580dbd 47
roger5641 5:4c6c92733561 48 DigitalOut fan1(D6);
roger5641 5:4c6c92733561 49 DigitalOut fan2(D7);
roger5641 5:4c6c92733561 50 DigitalOut fan3(D8);
roger5641 5:4c6c92733561 51 DigitalOut fan4(D9);
roger5641 5:4c6c92733561 52
roger5641 5:4c6c92733561 53 DigitalOut led1(A1);
roger5641 5:4c6c92733561 54 DigitalOut led2(A0);
roger5641 5:4c6c92733561 55 DigitalOut led3(D3);
roger5641 5:4c6c92733561 56 DigitalOut led4(D4);
roger5641 5:4c6c92733561 57 DigitalOut led5(D5);
roger5641 5:4c6c92733561 58
roger5641 0:3547f7580dbd 59 //char get_char();
roger5641 0:3547f7580dbd 60 void print_menu();
roger5641 0:3547f7580dbd 61 void read_config_data(uint8_t cfg_data[][6], uint8_t nIC);
roger5641 0:3547f7580dbd 62 void print_cells(uint8_t datalog_en);
roger5641 0:3547f7580dbd 63 void print_open();
roger5641 0:3547f7580dbd 64 void print_config();
roger5641 0:3547f7580dbd 65 void print_rxconfig();
roger5641 0:3547f7580dbd 66 void print_aux(uint8_t datalog_en);
roger5641 0:3547f7580dbd 67 void print_stat();
roger5641 0:3547f7580dbd 68 void check_error(int error);
roger5641 0:3547f7580dbd 69 /**********************************************************
roger5641 0:3547f7580dbd 70 Setup Variables
roger5641 0:3547f7580dbd 71 The following variables can be modified to
roger5641 0:3547f7580dbd 72 configure the software.
roger5641 0:3547f7580dbd 73
roger5641 0:3547f7580dbd 74 ***********************************************************/
roger5641 0:3547f7580dbd 75 const uint8_t TOTAL_IC = 1;//!<number of ICs in the daisy chain
roger5641 0:3547f7580dbd 76
roger5641 0:3547f7580dbd 77 //ADC Command Configurations
roger5641 0:3547f7580dbd 78 const uint8_t ADC_OPT = ADC_OPT_DISABLED; // See LTC6811_daisy.h for Options
roger5641 0:3547f7580dbd 79 const uint8_t ADC_CONVERSION_MODE = MD_7KHZ_3KHZ;//MD_7KHZ_3KHZ; //MD_26HZ_2KHZ;//MD_7KHZ_3KHZ; // See LTC6811_daisy.h for Options
roger5641 0:3547f7580dbd 80 const uint8_t ADC_DCP = DCP_DISABLED; // See LTC6811_daisy.h for Options
roger5641 0:3547f7580dbd 81 const uint8_t CELL_CH_TO_CONVERT = CELL_CH_ALL; // See LTC6811_daisy.h for Options
roger5641 0:3547f7580dbd 82 const uint8_t AUX_CH_TO_CONVERT = AUX_CH_ALL; // See LTC6811_daisy.h for Options
roger5641 0:3547f7580dbd 83 const uint8_t STAT_CH_TO_CONVERT = STAT_CH_ALL; // See LTC6811_daisy.h for Options
roger5641 0:3547f7580dbd 84
roger5641 0:3547f7580dbd 85 const uint16_t MEASUREMENT_LOOP_TIME = 500;//milliseconds(mS)
roger5641 0:3547f7580dbd 86
roger5641 0:3547f7580dbd 87 //Under Voltage and Over Voltage Thresholds
roger5641 0:3547f7580dbd 88 const uint16_t OV_THRESHOLD = 41000; // Over voltage threshold ADC Code. LSB = 0.0001
roger5641 0:3547f7580dbd 89 const uint16_t UV_THRESHOLD = 30000; // Under voltage threshold ADC Code. LSB = 0.0001
roger5641 0:3547f7580dbd 90
roger5641 0:3547f7580dbd 91 //Loop Measurement Setup These Variables are ENABLED or DISABLED Remember ALL CAPS
roger5641 0:3547f7580dbd 92 const uint8_t WRITE_CONFIG = DISABLED; // This is ENABLED or DISABLED
roger5641 0:3547f7580dbd 93 const uint8_t READ_CONFIG = DISABLED; // This is ENABLED or DISABLED
roger5641 0:3547f7580dbd 94 const uint8_t MEASURE_CELL = ENABLED; // This is ENABLED or DISABLED
roger5641 0:3547f7580dbd 95 const uint8_t MEASURE_AUX = DISABLED; // This is ENABLED or DISABLED
roger5641 0:3547f7580dbd 96 const uint8_t MEASURE_STAT = DISABLED; //This is ENABLED or DISABLED
roger5641 0:3547f7580dbd 97 const uint8_t PRINT_PEC = DISABLED; //This is ENABLED or DISABLED
roger5641 0:3547f7580dbd 98 /************************************
roger5641 0:3547f7580dbd 99 END SETUP
roger5641 0:3547f7580dbd 100 *************************************/
roger5641 0:3547f7580dbd 101
roger5641 0:3547f7580dbd 102 /******************************************************
roger5641 0:3547f7580dbd 103 *** Global Battery Variables received from 681x commands
roger5641 0:3547f7580dbd 104 These variables store the results from the LTC6811
roger5641 0:3547f7580dbd 105 register reads and the array lengths must be based
roger5641 0:3547f7580dbd 106 on the number of ICs on the stack
roger5641 0:3547f7580dbd 107 ******************************************************/
roger5641 0:3547f7580dbd 108
roger5641 0:3547f7580dbd 109 cell_asic bms_ic[TOTAL_IC];
roger5641 0:3547f7580dbd 110 void run_command(uint32_t cmd);
roger5641 0:3547f7580dbd 111 void measurement_loop(uint8_t datalog_en);
roger5641 0:3547f7580dbd 112 void print_pec(void);
roger5641 0:3547f7580dbd 113 void serial_print_hex(uint8_t data);
roger5641 0:3547f7580dbd 114
roger5641 0:3547f7580dbd 115
roger5641 0:3547f7580dbd 116 /*!*********************************************************************
roger5641 0:3547f7580dbd 117 \brief main loop
roger5641 0:3547f7580dbd 118 ***********************************************************************/
roger5641 0:3547f7580dbd 119 int main(void)
roger5641 0:3547f7580dbd 120 {
roger5641 2:e0ec3ed506ea 121 pc.baud(115200);
roger5641 2:e0ec3ed506ea 122 CS_PIN = 1;
roger5641 2:e0ec3ed506ea 123 spi.format(16,3);
roger5641 2:e0ec3ed506ea 124 spi.frequency(1000000); // 1MHz clock rate
roger5641 2:e0ec3ed506ea 125
roger5641 2:e0ec3ed506ea 126 LTC681x_init_cfg(TOTAL_IC, bms_ic);
roger5641 2:e0ec3ed506ea 127 LTC681x_reset_crc_count(TOTAL_IC,bms_ic);
roger5641 2:e0ec3ed506ea 128 LTC6811_init_reg_limits(TOTAL_IC,bms_ic);
roger5641 2:e0ec3ed506ea 129 print_menu();
roger5641 2:e0ec3ed506ea 130
roger5641 2:e0ec3ed506ea 131 while(1)
roger5641 2:e0ec3ed506ea 132 {
roger5641 2:e0ec3ed506ea 133 if (pc.readable()) // Check for user input
roger5641 2:e0ec3ed506ea 134 {
roger5641 2:e0ec3ed506ea 135 uint32_t user_command;
roger5641 2:e0ec3ed506ea 136 user_command = read_int(); // Read the user command
roger5641 4:47d6a0b63e38 137 pc.printf("%d\n",user_command);
roger5641 2:e0ec3ed506ea 138 run_command(user_command);
roger5641 2:e0ec3ed506ea 139 }
roger5641 2:e0ec3ed506ea 140 }
roger5641 0:3547f7580dbd 141 }
roger5641 0:3547f7580dbd 142
roger5641 0:3547f7580dbd 143
roger5641 0:3547f7580dbd 144 /*!*****************************************
roger5641 0:3547f7580dbd 145 \brief executes the user command
roger5641 0:3547f7580dbd 146 *******************************************/
roger5641 0:3547f7580dbd 147
roger5641 0:3547f7580dbd 148 void run_command(uint32_t cmd)
roger5641 0:3547f7580dbd 149 {
roger5641 0:3547f7580dbd 150 int8_t error = 0;
roger5641 0:3547f7580dbd 151 uint32_t conv_time = 0;
roger5641 5:4c6c92733561 152 // uint32_t user_command;
roger5641 0:3547f7580dbd 153 int8_t readIC=0;
roger5641 0:3547f7580dbd 154 char input = 0;
roger5641 0:3547f7580dbd 155 switch (cmd)
roger5641 0:3547f7580dbd 156 {
roger5641 0:3547f7580dbd 157
roger5641 0:3547f7580dbd 158 case 1: // Write Configuration Register
roger5641 0:3547f7580dbd 159 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 160 LTC681x_wrcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 161 print_config();
roger5641 0:3547f7580dbd 162 break;
roger5641 0:3547f7580dbd 163
roger5641 0:3547f7580dbd 164 case 2: // Read Configuration Register
roger5641 0:3547f7580dbd 165 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 166 error = LTC681x_rdcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 167 check_error(error);
roger5641 0:3547f7580dbd 168 print_rxconfig();
roger5641 0:3547f7580dbd 169 break;
roger5641 0:3547f7580dbd 170
roger5641 0:3547f7580dbd 171 case 3: // Start Cell ADC Measurement
roger5641 0:3547f7580dbd 172 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 173 LTC681x_adcv(ADC_CONVERSION_MODE,ADC_DCP,CELL_CH_TO_CONVERT);
roger5641 2:e0ec3ed506ea 174 conv_time = LTC681x_pollAdc();
roger5641 0:3547f7580dbd 175 pc.printf("cell conversion completed in:");
roger5641 0:3547f7580dbd 176 pc.printf("%.1f",((float)conv_time/1000));
roger5641 0:3547f7580dbd 177 pc.printf("mS");
roger5641 4:47d6a0b63e38 178 pc.printf("\n\r");
roger5641 0:3547f7580dbd 179 break;
roger5641 0:3547f7580dbd 180
roger5641 0:3547f7580dbd 181 case 4: // Read Cell Voltage Registers
roger5641 0:3547f7580dbd 182 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 183 error = LTC681x_rdcv(0, TOTAL_IC,bms_ic); // Set to read back all cell voltage registers
roger5641 0:3547f7580dbd 184 check_error(error);
roger5641 0:3547f7580dbd 185 print_cells(DATALOG_DISABLED);
roger5641 0:3547f7580dbd 186 break;
roger5641 0:3547f7580dbd 187
roger5641 0:3547f7580dbd 188 case 5: // Start GPIO ADC Measurement
roger5641 0:3547f7580dbd 189 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 190 LTC681x_adax(ADC_CONVERSION_MODE , AUX_CH_TO_CONVERT);
roger5641 2:e0ec3ed506ea 191 LTC681x_pollAdc();
roger5641 0:3547f7580dbd 192 pc.printf("aux conversion completed");
roger5641 4:47d6a0b63e38 193 pc.printf("\n\r");
roger5641 0:3547f7580dbd 194 break;
roger5641 0:3547f7580dbd 195
roger5641 0:3547f7580dbd 196 case 6: // Read AUX Voltage Registers
roger5641 0:3547f7580dbd 197 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 198 error = LTC681x_rdaux(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
roger5641 0:3547f7580dbd 199 check_error(error);
roger5641 0:3547f7580dbd 200 print_aux(DATALOG_DISABLED);
roger5641 0:3547f7580dbd 201 break;
roger5641 0:3547f7580dbd 202
roger5641 0:3547f7580dbd 203 case 7: // Start Status ADC Measurement
roger5641 0:3547f7580dbd 204 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 205 LTC681x_adstat(ADC_CONVERSION_MODE, STAT_CH_TO_CONVERT);
roger5641 2:e0ec3ed506ea 206 LTC681x_pollAdc();
roger5641 0:3547f7580dbd 207 pc.printf("stat conversion completed");
roger5641 4:47d6a0b63e38 208 pc.printf("\n\r");
roger5641 0:3547f7580dbd 209 break;
roger5641 0:3547f7580dbd 210
roger5641 0:3547f7580dbd 211 case 8: // Read Status registers
roger5641 0:3547f7580dbd 212 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 213 error = LTC681x_rdstat(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
roger5641 0:3547f7580dbd 214 check_error(error);
roger5641 0:3547f7580dbd 215 print_stat();
roger5641 0:3547f7580dbd 216 break;
roger5641 0:3547f7580dbd 217
roger5641 0:3547f7580dbd 218 case 9: // Loop Measurements
roger5641 0:3547f7580dbd 219 pc.printf("transmit 'm' to quit");
roger5641 0:3547f7580dbd 220 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 221 LTC681x_wrcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 222 while (input != 'm')
roger5641 0:3547f7580dbd 223 {
roger5641 0:3547f7580dbd 224 if (pc.readable() > 0)
roger5641 0:3547f7580dbd 225 {
roger5641 0:3547f7580dbd 226 input = read_char();
roger5641 0:3547f7580dbd 227 }
roger5641 0:3547f7580dbd 228
roger5641 0:3547f7580dbd 229 measurement_loop(DATALOG_DISABLED);
roger5641 0:3547f7580dbd 230
roger5641 0:3547f7580dbd 231 wait_ms(MEASUREMENT_LOOP_TIME);
roger5641 0:3547f7580dbd 232 }
roger5641 0:3547f7580dbd 233 //print_menu();
roger5641 0:3547f7580dbd 234 break;
roger5641 0:3547f7580dbd 235
roger5641 0:3547f7580dbd 236 case 10: // Run open wire self test
roger5641 0:3547f7580dbd 237 print_pec();
roger5641 0:3547f7580dbd 238
roger5641 0:3547f7580dbd 239 break;
roger5641 0:3547f7580dbd 240
roger5641 0:3547f7580dbd 241 case 11: // Read in raw configuration data
roger5641 2:e0ec3ed506ea 242 LTC681x_reset_crc_count(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 243 break;
roger5641 0:3547f7580dbd 244
roger5641 0:3547f7580dbd 245 case 12: // Run the ADC/Memory Self Test
roger5641 0:3547f7580dbd 246 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 247 error = LTC681x_run_cell_adc_st(CELL,ADC_CONVERSION_MODE,bms_ic);
roger5641 0:3547f7580dbd 248 pc.printf("%d",error);
roger5641 0:3547f7580dbd 249 pc.printf(" : errors detected in Digital Filter and CELL Memory \n");
roger5641 0:3547f7580dbd 250
roger5641 0:3547f7580dbd 251 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 252 error = LTC681x_run_cell_adc_st(AUX,ADC_CONVERSION_MODE, bms_ic);
roger5641 0:3547f7580dbd 253 pc.printf("%d",error);
roger5641 0:3547f7580dbd 254 pc.printf(" : errors detected in Digital Filter and AUX Memory \n");
roger5641 0:3547f7580dbd 255
roger5641 0:3547f7580dbd 256 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 257 error = LTC681x_run_cell_adc_st(STAT,ADC_CONVERSION_MODE, bms_ic);
roger5641 0:3547f7580dbd 258 pc.printf("%d",error);
roger5641 0:3547f7580dbd 259 pc.printf(" : errors detected in Digital Filter and STAT Memory \n");
roger5641 0:3547f7580dbd 260 print_menu();
roger5641 0:3547f7580dbd 261 break;
roger5641 0:3547f7580dbd 262
roger5641 0:3547f7580dbd 263 case 13: // Enable a discharge transistor
roger5641 0:3547f7580dbd 264 pc.printf("Please enter the Spin number");
roger5641 0:3547f7580dbd 265 readIC = (int8_t)read_int();
roger5641 0:3547f7580dbd 266 LTC6811_set_discharge(readIC,TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 267 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 268 LTC681x_wrcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 269 print_config();
roger5641 0:3547f7580dbd 270 break;
roger5641 0:3547f7580dbd 271
roger5641 0:3547f7580dbd 272 case 14: // Clear all discharge transistors
roger5641 0:3547f7580dbd 273 clear_discharge(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 274 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 275 LTC681x_wrcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 276 print_config();
roger5641 0:3547f7580dbd 277 break;
roger5641 0:3547f7580dbd 278
roger5641 0:3547f7580dbd 279 case 15: // Clear all ADC measurement registers
roger5641 0:3547f7580dbd 280 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 281 LTC681x_clrcell();
roger5641 2:e0ec3ed506ea 282 LTC681x_clraux();
roger5641 2:e0ec3ed506ea 283 LTC681x_clrstat();
roger5641 4:47d6a0b63e38 284 pc.printf("All Registers Cleared\n");
roger5641 0:3547f7580dbd 285 break;
roger5641 0:3547f7580dbd 286
roger5641 0:3547f7580dbd 287 case 16: // Run the Mux Decoder Self Test
roger5641 0:3547f7580dbd 288 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 289 LTC681x_diagn();
roger5641 0:3547f7580dbd 290 wait_ms(5);
roger5641 2:e0ec3ed506ea 291 error = LTC681x_rdstat(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
roger5641 0:3547f7580dbd 292 check_error(error);
roger5641 0:3547f7580dbd 293 error = 0;
roger5641 0:3547f7580dbd 294 for (int ic = 0; ic<TOTAL_IC; ic++)
roger5641 0:3547f7580dbd 295 {
roger5641 0:3547f7580dbd 296 if (bms_ic[ic].stat.mux_fail[0] != 0) error++;
roger5641 0:3547f7580dbd 297 }
roger5641 0:3547f7580dbd 298 if (error==0) pc.printf("Mux Test: PASS ");
roger5641 0:3547f7580dbd 299 else pc.printf("Mux Test: FAIL ");
roger5641 0:3547f7580dbd 300
roger5641 0:3547f7580dbd 301 break;
roger5641 0:3547f7580dbd 302
roger5641 0:3547f7580dbd 303 case 17: // Run ADC Overlap self test
roger5641 0:3547f7580dbd 304 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 305 error = (int8_t)LTC681x_run_adc_overlap(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 306 if (error==0) pc.printf("Overlap Test: PASS ");
roger5641 0:3547f7580dbd 307 else pc.printf("Overlap Test: FAIL");
roger5641 0:3547f7580dbd 308 break;
roger5641 0:3547f7580dbd 309
roger5641 0:3547f7580dbd 310 case 18: // Run ADC Redundancy self test
roger5641 0:3547f7580dbd 311 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 312 error = LTC681x_run_adc_redundancy_st(ADC_CONVERSION_MODE,AUX,TOTAL_IC, bms_ic);
roger5641 0:3547f7580dbd 313 pc.printf("%d",error);
roger5641 0:3547f7580dbd 314 pc.printf(" : errors detected in AUX Measurement \n");
roger5641 0:3547f7580dbd 315
roger5641 0:3547f7580dbd 316 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 317 error = LTC681x_run_adc_redundancy_st(ADC_CONVERSION_MODE,STAT,TOTAL_IC, bms_ic);
roger5641 0:3547f7580dbd 318 pc.printf("%d",error);
roger5641 0:3547f7580dbd 319 pc.printf(" : errors detected in STAT Measurement \n");
roger5641 0:3547f7580dbd 320 break;
roger5641 0:3547f7580dbd 321
roger5641 0:3547f7580dbd 322 case 19:
roger5641 2:e0ec3ed506ea 323 LTC681x_run_openwire(TOTAL_IC, bms_ic);
roger5641 0:3547f7580dbd 324 print_open();
roger5641 0:3547f7580dbd 325 break;
roger5641 0:3547f7580dbd 326
roger5641 0:3547f7580dbd 327 case 20: //Datalog print option Loop Measurements
roger5641 0:3547f7580dbd 328 pc.printf("transmit 'm' to quit");
roger5641 0:3547f7580dbd 329 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 330 LTC681x_wrcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 331 while (input != 'm')
roger5641 0:3547f7580dbd 332 {
roger5641 0:3547f7580dbd 333 if (pc.readable() > 0)
roger5641 0:3547f7580dbd 334 {
roger5641 0:3547f7580dbd 335 input = read_char();
roger5641 0:3547f7580dbd 336 }
roger5641 0:3547f7580dbd 337
roger5641 0:3547f7580dbd 338 measurement_loop(DATALOG_ENABLED);
roger5641 0:3547f7580dbd 339
roger5641 0:3547f7580dbd 340 wait_ms(MEASUREMENT_LOOP_TIME);
roger5641 0:3547f7580dbd 341 }
roger5641 0:3547f7580dbd 342 print_menu();
roger5641 0:3547f7580dbd 343 break;
roger5641 0:3547f7580dbd 344
roger5641 0:3547f7580dbd 345 case 'm': //prints menu
roger5641 0:3547f7580dbd 346 print_menu();
roger5641 0:3547f7580dbd 347 break;
roger5641 0:3547f7580dbd 348
roger5641 0:3547f7580dbd 349 default:
roger5641 4:47d6a0b63e38 350 pc.printf("Incorrect Option\n");
roger5641 0:3547f7580dbd 351 break;
roger5641 0:3547f7580dbd 352 }
roger5641 0:3547f7580dbd 353 }
roger5641 0:3547f7580dbd 354
roger5641 0:3547f7580dbd 355 void measurement_loop(uint8_t datalog_en)
roger5641 0:3547f7580dbd 356 {
roger5641 0:3547f7580dbd 357 int8_t error = 0;
roger5641 0:3547f7580dbd 358 if (WRITE_CONFIG == ENABLED)
roger5641 0:3547f7580dbd 359 {
roger5641 0:3547f7580dbd 360 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 361 LTC681x_wrcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 362 print_config();
roger5641 0:3547f7580dbd 363 }
roger5641 0:3547f7580dbd 364
roger5641 0:3547f7580dbd 365 if (READ_CONFIG == ENABLED)
roger5641 0:3547f7580dbd 366 {
roger5641 0:3547f7580dbd 367 wakeup_sleep(TOTAL_IC);
roger5641 2:e0ec3ed506ea 368 error = LTC681x_rdcfg(TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 369 check_error(error);
roger5641 0:3547f7580dbd 370 print_rxconfig();
roger5641 0:3547f7580dbd 371 }
roger5641 0:3547f7580dbd 372
roger5641 0:3547f7580dbd 373 if (MEASURE_CELL == ENABLED)
roger5641 0:3547f7580dbd 374 {
roger5641 0:3547f7580dbd 375 wakeup_idle(TOTAL_IC);
roger5641 2:e0ec3ed506ea 376 LTC681x_adcv(ADC_CONVERSION_MODE,ADC_DCP,CELL_CH_TO_CONVERT);
roger5641 2:e0ec3ed506ea 377 LTC681x_pollAdc();
roger5641 0:3547f7580dbd 378 wakeup_idle(TOTAL_IC);
roger5641 2:e0ec3ed506ea 379 error = LTC681x_rdcv(0, TOTAL_IC,bms_ic);
roger5641 0:3547f7580dbd 380 check_error(error);
roger5641 0:3547f7580dbd 381 print_cells(datalog_en);
roger5641 0:3547f7580dbd 382
roger5641 0:3547f7580dbd 383 }
roger5641 0:3547f7580dbd 384
roger5641 0:3547f7580dbd 385 if (MEASURE_AUX == ENABLED)
roger5641 0:3547f7580dbd 386 {
roger5641 0:3547f7580dbd 387 wakeup_idle(TOTAL_IC);
roger5641 2:e0ec3ed506ea 388 LTC681x_adax(ADC_CONVERSION_MODE , AUX_CH_ALL);
roger5641 2:e0ec3ed506ea 389 LTC681x_pollAdc();
roger5641 0:3547f7580dbd 390 wakeup_idle(TOTAL_IC);
roger5641 2:e0ec3ed506ea 391 error = LTC681x_rdaux(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
roger5641 0:3547f7580dbd 392 check_error(error);
roger5641 0:3547f7580dbd 393 print_aux(datalog_en);
roger5641 0:3547f7580dbd 394 }
roger5641 0:3547f7580dbd 395
roger5641 0:3547f7580dbd 396 if (MEASURE_STAT == ENABLED)
roger5641 0:3547f7580dbd 397 {
roger5641 0:3547f7580dbd 398 wakeup_idle(TOTAL_IC);
roger5641 2:e0ec3ed506ea 399 LTC681x_adstat(ADC_CONVERSION_MODE, STAT_CH_ALL);
roger5641 2:e0ec3ed506ea 400 LTC681x_pollAdc();
roger5641 0:3547f7580dbd 401 wakeup_idle(TOTAL_IC);
roger5641 2:e0ec3ed506ea 402 error = LTC681x_rdstat(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
roger5641 0:3547f7580dbd 403 check_error(error);
roger5641 0:3547f7580dbd 404 print_stat();
roger5641 0:3547f7580dbd 405 }
roger5641 0:3547f7580dbd 406
roger5641 0:3547f7580dbd 407 if (PRINT_PEC == ENABLED)
roger5641 0:3547f7580dbd 408 {
roger5641 0:3547f7580dbd 409 print_pec();
roger5641 0:3547f7580dbd 410 }
roger5641 0:3547f7580dbd 411
roger5641 0:3547f7580dbd 412 }
roger5641 0:3547f7580dbd 413
roger5641 0:3547f7580dbd 414
roger5641 0:3547f7580dbd 415 /*!*********************************
roger5641 0:3547f7580dbd 416 \brief Prints the main menu
roger5641 0:3547f7580dbd 417 ***********************************/
roger5641 0:3547f7580dbd 418 void print_menu()
roger5641 0:3547f7580dbd 419 {
roger5641 4:47d6a0b63e38 420 pc.printf("Please enter LTC6811 Command\n");
roger5641 4:47d6a0b63e38 421 pc.printf("Write Configuration: 1 | Reset PEC Counter: 11\n");
roger5641 4:47d6a0b63e38 422 pc.printf("Read Configuration: 2 | Run ADC Self Test: 12\n");
roger5641 4:47d6a0b63e38 423 pc.printf("Start Cell Voltage Conversion: 3 | Set Discharge: 13\n");
roger5641 4:47d6a0b63e38 424 pc.printf("Read Cell Voltages: 4 | Clear Discharge: 14\n");
roger5641 4:47d6a0b63e38 425 pc.printf("Start Aux Voltage Conversion: 5 | Clear Registers: 15\n");
roger5641 4:47d6a0b63e38 426 pc.printf("Read Aux Voltages: 6 | Run Mux Self Test: 16\n");
roger5641 4:47d6a0b63e38 427 pc.printf("Start Stat Voltage Conversion: 7 | Run ADC overlap Test: 17\n");
roger5641 4:47d6a0b63e38 428 pc.printf("Read Stat Voltages: 8 | Run Digital Redundancy Test: 18\n");
roger5641 4:47d6a0b63e38 429 pc.printf("loop Measurements: 9 | Run Open Wire Test: 19\n");
roger5641 4:47d6a0b63e38 430 pc.printf("Read PEC Errors: 10 | Loop measurements with datalog output: 20\n");
roger5641 0:3547f7580dbd 431 pc.printf("\r");
roger5641 4:47d6a0b63e38 432 pc.printf("Please enter command: \n");
roger5641 0:3547f7580dbd 433 pc.printf("\r");
roger5641 0:3547f7580dbd 434 }
roger5641 0:3547f7580dbd 435
roger5641 0:3547f7580dbd 436 /*!************************************************************
roger5641 0:3547f7580dbd 437 \brief Prints cell voltage codes to the pc port
roger5641 0:3547f7580dbd 438 *************************************************************/
roger5641 0:3547f7580dbd 439 void print_cells(uint8_t datalog_en)
roger5641 0:3547f7580dbd 440 {
roger5641 0:3547f7580dbd 441 for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++)
roger5641 0:3547f7580dbd 442 {
roger5641 0:3547f7580dbd 443 if (datalog_en == 0)
roger5641 0:3547f7580dbd 444 {
roger5641 0:3547f7580dbd 445 pc.printf(" IC ");
roger5641 0:3547f7580dbd 446 pc.printf("%d",current_ic+1);
roger5641 0:3547f7580dbd 447 pc.printf(", ");
roger5641 0:3547f7580dbd 448 for (int i=0; i<bms_ic[0].ic_reg.cell_channels; i++)
roger5641 0:3547f7580dbd 449 {
roger5641 0:3547f7580dbd 450
roger5641 0:3547f7580dbd 451 pc.printf(" C");
roger5641 0:3547f7580dbd 452 pc.printf("%d",i+1);
roger5641 0:3547f7580dbd 453 pc.printf(":");
roger5641 0:3547f7580dbd 454 pc.printf("%.4f",bms_ic[current_ic].cells.c_codes[i]*0.0001);
roger5641 0:3547f7580dbd 455 pc.printf(",");
roger5641 0:3547f7580dbd 456 }
roger5641 0:3547f7580dbd 457 pc.printf("\r");
roger5641 0:3547f7580dbd 458 }
roger5641 0:3547f7580dbd 459 else
roger5641 0:3547f7580dbd 460 {
roger5641 0:3547f7580dbd 461 pc.printf("Cells, ");
roger5641 0:3547f7580dbd 462 for (int i=0; i<bms_ic[0].ic_reg.cell_channels; i++)
roger5641 0:3547f7580dbd 463 {
roger5641 0:3547f7580dbd 464 pc.printf("%.4f",bms_ic[current_ic].cells.c_codes[i]*0.0001);
roger5641 0:3547f7580dbd 465 pc.printf(",");
roger5641 0:3547f7580dbd 466 }
roger5641 0:3547f7580dbd 467
roger5641 0:3547f7580dbd 468 }
roger5641 0:3547f7580dbd 469 }
roger5641 4:47d6a0b63e38 470 pc.printf("\n\r");
roger5641 0:3547f7580dbd 471 }
roger5641 0:3547f7580dbd 472
roger5641 0:3547f7580dbd 473 /*!****************************************************************************
roger5641 0:3547f7580dbd 474 \brief Prints Open wire test results to the pc port
roger5641 0:3547f7580dbd 475 *****************************************************************************/
roger5641 0:3547f7580dbd 476 void print_open()
roger5641 0:3547f7580dbd 477 {
roger5641 0:3547f7580dbd 478 for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++)
roger5641 0:3547f7580dbd 479 {
roger5641 0:3547f7580dbd 480 if (bms_ic[current_ic].system_open_wire == 0)
roger5641 0:3547f7580dbd 481 {
roger5641 0:3547f7580dbd 482 pc.printf("No Opens Detected on IC: ");
roger5641 0:3547f7580dbd 483 pc.printf("%d",current_ic+1);
roger5641 0:3547f7580dbd 484 pc.printf("\r");
roger5641 0:3547f7580dbd 485 }
roger5641 0:3547f7580dbd 486 else
roger5641 0:3547f7580dbd 487 {
roger5641 0:3547f7580dbd 488 for (int cell=0; cell<bms_ic[0].ic_reg.cell_channels+1; cell++)
roger5641 0:3547f7580dbd 489 {
roger5641 0:3547f7580dbd 490 if ((bms_ic[current_ic].system_open_wire &(1<<cell))>0)
roger5641 0:3547f7580dbd 491 {
roger5641 0:3547f7580dbd 492 pc.printf("There is an open wire on IC: ");
roger5641 0:3547f7580dbd 493 pc.printf("%d",current_ic + 1);
roger5641 0:3547f7580dbd 494 pc.printf(" Channel: ");
roger5641 0:3547f7580dbd 495 pc.printf("%d",cell);
roger5641 0:3547f7580dbd 496 }
roger5641 0:3547f7580dbd 497 }
roger5641 0:3547f7580dbd 498 }
roger5641 0:3547f7580dbd 499 }
roger5641 4:47d6a0b63e38 500 pc.printf("\n\r");
roger5641 0:3547f7580dbd 501 }
roger5641 0:3547f7580dbd 502
roger5641 0:3547f7580dbd 503 /*!****************************************************************************
roger5641 0:3547f7580dbd 504 \brief Prints GPIO voltage codes and Vref2 voltage code onto the pc port
roger5641 0:3547f7580dbd 505 *****************************************************************************/
roger5641 0:3547f7580dbd 506 void print_aux(uint8_t datalog_en)
roger5641 0:3547f7580dbd 507 {
roger5641 0:3547f7580dbd 508 for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++)
roger5641 0:3547f7580dbd 509 {
roger5641 0:3547f7580dbd 510 if (datalog_en == 0)
roger5641 0:3547f7580dbd 511 {
roger5641 0:3547f7580dbd 512 pc.printf(" IC ");
roger5641 0:3547f7580dbd 513 pc.printf("%d",current_ic+1);
roger5641 0:3547f7580dbd 514 for (int i=0; i < 5; i++)
roger5641 0:3547f7580dbd 515 {
roger5641 0:3547f7580dbd 516 pc.printf(" GPIO-");
roger5641 0:3547f7580dbd 517 pc.printf("%d",i+1);
roger5641 0:3547f7580dbd 518 pc.printf(":");
roger5641 0:3547f7580dbd 519 pc.printf("%.4f",bms_ic[current_ic].aux.a_codes[i]*0.0001);
roger5641 0:3547f7580dbd 520 pc.printf(",");
roger5641 0:3547f7580dbd 521 }
roger5641 0:3547f7580dbd 522 pc.printf(" Vref2");
roger5641 0:3547f7580dbd 523 pc.printf(":");
roger5641 0:3547f7580dbd 524 pc.printf("%.4f",bms_ic[current_ic].aux.a_codes[5]*0.0001);
roger5641 4:47d6a0b63e38 525 pc.printf("\n\r");
roger5641 0:3547f7580dbd 526 }
roger5641 0:3547f7580dbd 527 else
roger5641 0:3547f7580dbd 528 {
roger5641 0:3547f7580dbd 529 pc.printf("AUX, ");
roger5641 0:3547f7580dbd 530
roger5641 0:3547f7580dbd 531 for (int i=0; i < 6; i++)
roger5641 0:3547f7580dbd 532 {
roger5641 0:3547f7580dbd 533 pc.printf("%.4f",bms_ic[current_ic].aux.a_codes[i]*0.0001);
roger5641 0:3547f7580dbd 534 pc.printf(",");
roger5641 0:3547f7580dbd 535 }
roger5641 0:3547f7580dbd 536 }
roger5641 0:3547f7580dbd 537 }
roger5641 4:47d6a0b63e38 538 pc.printf("\n\r");
roger5641 0:3547f7580dbd 539 }
roger5641 0:3547f7580dbd 540
roger5641 0:3547f7580dbd 541 /*!****************************************************************************
roger5641 0:3547f7580dbd 542 \brief Prints Status voltage codes and Vref2 voltage code onto the pc port
roger5641 0:3547f7580dbd 543 *****************************************************************************/
roger5641 0:3547f7580dbd 544 void print_stat()
roger5641 0:3547f7580dbd 545 {
roger5641 0:3547f7580dbd 546 for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++)
roger5641 0:3547f7580dbd 547 {
roger5641 0:3547f7580dbd 548 pc.printf(" IC ");
roger5641 0:3547f7580dbd 549 pc.printf("%d",current_ic+1);
roger5641 0:3547f7580dbd 550 pc.printf(" SOC:");
roger5641 0:3547f7580dbd 551 pc.printf("%.4f",bms_ic[current_ic].stat.stat_codes[0]*0.0001*20);
roger5641 0:3547f7580dbd 552 pc.printf(",");
roger5641 0:3547f7580dbd 553 pc.printf(" Itemp:");
roger5641 0:3547f7580dbd 554 pc.printf("%.4f",bms_ic[current_ic].stat.stat_codes[1]*0.0001);
roger5641 0:3547f7580dbd 555 pc.printf(",");
roger5641 0:3547f7580dbd 556 pc.printf(" VregA:");
roger5641 0:3547f7580dbd 557 pc.printf("%.4f",bms_ic[current_ic].stat.stat_codes[2]*0.0001);
roger5641 0:3547f7580dbd 558 pc.printf(",");
roger5641 0:3547f7580dbd 559 pc.printf(" VregD:");
roger5641 0:3547f7580dbd 560 pc.printf("%.4f",bms_ic[current_ic].stat.stat_codes[3]*0.0001);
roger5641 0:3547f7580dbd 561 pc.printf("\r");
roger5641 0:3547f7580dbd 562 }
roger5641 4:47d6a0b63e38 563 pc.printf("\n\r");
roger5641 0:3547f7580dbd 564 }
roger5641 0:3547f7580dbd 565
roger5641 0:3547f7580dbd 566 /*!******************************************************************************
roger5641 0:3547f7580dbd 567 \brief Prints the configuration data that is going to be written to the LTC6811
roger5641 0:3547f7580dbd 568 to the pc port.
roger5641 0:3547f7580dbd 569 ********************************************************************************/
roger5641 0:3547f7580dbd 570 void print_config()
roger5641 0:3547f7580dbd 571 {
roger5641 0:3547f7580dbd 572 int cfg_pec;
roger5641 0:3547f7580dbd 573
roger5641 0:3547f7580dbd 574 pc.printf("Written Configuration: ");
roger5641 0:3547f7580dbd 575 for (int current_ic = 0; current_ic<TOTAL_IC; current_ic++)
roger5641 0:3547f7580dbd 576 {
roger5641 0:3547f7580dbd 577 pc.printf(" IC ");
roger5641 0:3547f7580dbd 578 pc.printf("%d",current_ic+1);
roger5641 0:3547f7580dbd 579 pc.printf(": ");
roger5641 0:3547f7580dbd 580 pc.printf("0x");
roger5641 0:3547f7580dbd 581 serial_print_hex(bms_ic[current_ic].config.tx_data[0]);
roger5641 0:3547f7580dbd 582 pc.printf(", 0x");
roger5641 0:3547f7580dbd 583 serial_print_hex(bms_ic[current_ic].config.tx_data[1]);
roger5641 0:3547f7580dbd 584 pc.printf(", 0x");
roger5641 0:3547f7580dbd 585 serial_print_hex(bms_ic[current_ic].config.tx_data[2]);
roger5641 0:3547f7580dbd 586 pc.printf(", 0x");
roger5641 0:3547f7580dbd 587 serial_print_hex(bms_ic[current_ic].config.tx_data[3]);
roger5641 0:3547f7580dbd 588 pc.printf(", 0x");
roger5641 0:3547f7580dbd 589 serial_print_hex(bms_ic[current_ic].config.tx_data[4]);
roger5641 0:3547f7580dbd 590 pc.printf(", 0x");
roger5641 0:3547f7580dbd 591 serial_print_hex(bms_ic[current_ic].config.tx_data[5]);
roger5641 0:3547f7580dbd 592 pc.printf(", Calculated PEC: 0x");
roger5641 0:3547f7580dbd 593 cfg_pec = pec15_calc(6,&bms_ic[current_ic].config.tx_data[0]);
roger5641 0:3547f7580dbd 594 serial_print_hex((uint8_t)(cfg_pec>>8));
roger5641 0:3547f7580dbd 595 pc.printf(", 0x");
roger5641 0:3547f7580dbd 596 serial_print_hex((uint8_t)(cfg_pec));
roger5641 0:3547f7580dbd 597 pc.printf("\r");
roger5641 0:3547f7580dbd 598 }
roger5641 4:47d6a0b63e38 599 pc.printf("\n\r");
roger5641 0:3547f7580dbd 600 }
roger5641 0:3547f7580dbd 601
roger5641 0:3547f7580dbd 602 /*!*****************************************************************
roger5641 0:3547f7580dbd 603 \brief Prints the configuration data that was read back from the
roger5641 0:3547f7580dbd 604 LTC6811 to the pc port.
roger5641 0:3547f7580dbd 605 *******************************************************************/
roger5641 0:3547f7580dbd 606 void print_rxconfig()
roger5641 0:3547f7580dbd 607 {
roger5641 4:47d6a0b63e38 608 pc.printf("Received Configuration ");
roger5641 4:47d6a0b63e38 609 for (int current_ic=0; current_ic<TOTAL_IC; current_ic++)
roger5641 4:47d6a0b63e38 610 {
roger5641 4:47d6a0b63e38 611 pc.printf(" IC ");
roger5641 4:47d6a0b63e38 612 pc.printf("%d",current_ic+1);
roger5641 4:47d6a0b63e38 613 pc.printf(": 0x");
roger5641 4:47d6a0b63e38 614 serial_print_hex(bms_ic[current_ic].config.rx_data[0]);
roger5641 4:47d6a0b63e38 615 pc.printf(", 0x");
roger5641 4:47d6a0b63e38 616 serial_print_hex(bms_ic[current_ic].config.rx_data[1]);
roger5641 4:47d6a0b63e38 617 pc.printf(", 0x");
roger5641 4:47d6a0b63e38 618 serial_print_hex(bms_ic[current_ic].config.rx_data[2]);
roger5641 4:47d6a0b63e38 619 pc.printf(", 0x");
roger5641 4:47d6a0b63e38 620 serial_print_hex(bms_ic[current_ic].config.rx_data[3]);
roger5641 4:47d6a0b63e38 621 pc.printf(", 0x");
roger5641 4:47d6a0b63e38 622 serial_print_hex(bms_ic[current_ic].config.rx_data[4]);
roger5641 4:47d6a0b63e38 623 pc.printf(", 0x");
roger5641 4:47d6a0b63e38 624 serial_print_hex(bms_ic[current_ic].config.rx_data[5]);
roger5641 4:47d6a0b63e38 625 pc.printf(", Received PEC: 0x");
roger5641 4:47d6a0b63e38 626 serial_print_hex(bms_ic[current_ic].config.rx_data[6]);
roger5641 4:47d6a0b63e38 627 pc.printf(", 0x");
roger5641 4:47d6a0b63e38 628 serial_print_hex(bms_ic[current_ic].config.rx_data[7]);
roger5641 4:47d6a0b63e38 629 pc.printf("\r");
roger5641 4:47d6a0b63e38 630 }
roger5641 4:47d6a0b63e38 631 pc.printf("\n\r");
roger5641 0:3547f7580dbd 632 }
roger5641 0:3547f7580dbd 633
roger5641 0:3547f7580dbd 634 void print_pec()
roger5641 0:3547f7580dbd 635 {
roger5641 0:3547f7580dbd 636 for (int current_ic=0; current_ic<TOTAL_IC; current_ic++)
roger5641 0:3547f7580dbd 637 {
roger5641 0:3547f7580dbd 638 pc.printf("");
roger5641 0:3547f7580dbd 639 pc.printf("%d",bms_ic[current_ic].crc_count.pec_count);
roger5641 0:3547f7580dbd 640 pc.printf(" : PEC Errors Detected on IC");
roger5641 0:3547f7580dbd 641 pc.printf("%d",current_ic+1);
roger5641 0:3547f7580dbd 642 }
roger5641 4:47d6a0b63e38 643 pc.printf("\n\r");
roger5641 0:3547f7580dbd 644 }
roger5641 0:3547f7580dbd 645
roger5641 0:3547f7580dbd 646
roger5641 0:3547f7580dbd 647 void serial_print_hex(uint8_t data)
roger5641 0:3547f7580dbd 648 {
roger5641 0:3547f7580dbd 649 if (data< 16)
roger5641 0:3547f7580dbd 650 {
roger5641 0:3547f7580dbd 651 pc.printf("0");
roger5641 0:3547f7580dbd 652 pc.printf("%X",data);
roger5641 0:3547f7580dbd 653 }
roger5641 0:3547f7580dbd 654 else
roger5641 0:3547f7580dbd 655 pc.printf("%X",data);
roger5641 0:3547f7580dbd 656 }
roger5641 0:3547f7580dbd 657
roger5641 0:3547f7580dbd 658 //Function to check error flag and print PEC error message
roger5641 0:3547f7580dbd 659 void check_error(int error)
roger5641 0:3547f7580dbd 660 {
roger5641 0:3547f7580dbd 661 if (error == -1)
roger5641 0:3547f7580dbd 662 {
roger5641 4:47d6a0b63e38 663 pc.printf("A PEC error was detected in the received data\n");
roger5641 0:3547f7580dbd 664 }
roger5641 0:3547f7580dbd 665 }