BMS_T2

Dependencies:   INA226

Revision:
2:3bbbe439ec11
Parent:
0:f06ed53310a3
Child:
3:61174d4de67d
--- a/main.cpp	Fri Feb 09 04:43:04 2018 +0000
+++ b/main.cpp	Tue Oct 13 06:26:34 2020 +0000
@@ -3,6 +3,11 @@
 #include "bms.h"
 #include "LTC681x.h"
 #include "LTC6811.h"
+#include "CAN.h"
+#include "INA226.hpp"
+#include "max6675.h"
+#include "max6675_2.h"
+
 
 #define UI_BUFFER_SIZE 64
 #define SERIAL_TERMINATOR '\n'
@@ -12,12 +17,26 @@
 
 #define DATALOG_ENABLED 1
 #define DATALOG_DISABLED 0
+
+
+
 DigitalOut led1(LED1);
 Serial pc(USBTX, USBRX);
+CAN can1(p9,p10);
+CAN can2(p30,p29);
+I2C i2c(p28,p27);
+DigitalOut BAT_MIN_safty(p21);
+DigitalOut BAT_MAX_safty(p22);
+INA226 VCmonitor(i2c);
+SPI spi(p11,p12,p13);
+max6675 max(spi,p18);
+SPI spi_2(p11,p12,p13);
+max6675_2 max_2(spi_2,p21);
+
 
 void run_command(uint32_t cmd);
 void measurement_loop(uint8_t datalog_en);
-void print_menu();
+//void print_menu();
 void print_cells(uint8_t datalog_en);
 void print_open();
 void print_aux(uint8_t datalog_en);
@@ -27,16 +46,26 @@
 void print_pec(void);
 void serial_print_hex(uint8_t data);
 void check_error(int error);
+void wakeup();
+void cell_read();
+void spi_error();
+void ic_check();
+void spi_check();
+void print_CAN(uint8_t datalog_en);
+void print_math();
+void can_sent1();
+void can_sent2();
+void can_sent3();
+void can_sent4();
+//void can_set();
+void can_wait();
+void ic_set();
+
+
 //char get_char();
 //void read_config_data(uint8_t cfg_data[][6], uint8_t nIC);
 
-/**********************************************************
-  Setup Variables
-  The following variables can be modified to
-  configure the software.
-
-***********************************************************/
-const uint8_t TOTAL_IC = 1;//!<number of ICs in the daisy chain
+const uint8_t TOTAL_IC = 3;//!<number of ICs in the daisy chain
 char ui_buffer[UI_BUFFER_SIZE];
 
 
@@ -48,11 +77,11 @@
 const uint8_t AUX_CH_TO_CONVERT = AUX_CH_ALL; // See LTC6811_daisy.h for Options
 const uint8_t STAT_CH_TO_CONVERT = STAT_CH_ALL; // See LTC6811_daisy.h for Options
 
-const uint16_t MEASUREMENT_LOOP_TIME = 500;//milliseconds(mS)
+const uint16_t MEASUREMENT_LOOP_TIME = 100;//milliseconds(mS)
 
 //Under Voltage and Over Voltage Thresholds
-const uint16_t OV_THRESHOLD = 41000; // Over voltage threshold ADC Code. LSB = 0.0001
-const uint16_t UV_THRESHOLD = 30000; // Under voltage threshold ADC Code. LSB = 0.0001
+const uint16_t OV_THRESHOLD = 41000; //
+const uint16_t UV_THRESHOLD = 30000; // 
 
 //Loop Measurement Setup These Variables are ENABLED or DISABLED Remember ALL CAPS
 const uint8_t WRITE_CONFIG = DISABLED; // This is ENABLED or DISABLED
@@ -61,275 +90,344 @@
 const uint8_t MEASURE_AUX = DISABLED; // This is ENABLED or DISABLED
 const uint8_t MEASURE_STAT = DISABLED; //This is ENABLED or DISABLED
 const uint8_t PRINT_PEC = DISABLED; //This is ENABLED or DISABLED
-
+short n =0;
 
-// Read data from the serial interface into the ui_buffer buffer
 uint8_t read_data();
 
-// Read a float value from the serial interface
 float read_float();
 
-// Read an integer from the serial interface.
-// The routine can recognize Hex, Decimal, Octal, or Binary
-// Example:
-// Hex:     0x11 (0x prefix)
-// Decimal: 17
-// Octal:   O21 (leading letter O prefix)
-// Binary:  B10001 (leading letter B prefix)
+
 int32_t read_int();
 
-// Read a string from the serial interface.  Returns a pointer to the ui_buffer.
-char *read_string();
-
-// Read a character from the serial interface
-int8_t read_char();
+int BAT_MIN, BAT_MAX, BAT_AVG;
+double BAT_Current;
+long BAT_SUM;
+unsigned short BAT_CELL[27];
 
-/************************************
-  END SETUP
-*************************************/
-
-/******************************************************
- *** Global Battery Variables received from 681x commands
- These variables store the results from the LTC6811
- register reads and the array lengths must be based
- on the number of ICs on the stack
- ******************************************************/
+char *read_string();
+int8_t read_char();
 
 cell_asic bms_ic[TOTAL_IC];
 
-/*!*********************************************************************
-  \brief main loop
-***********************************************************************/
 int main(void)
 {
     uint32_t user_command;
     
     pc.baud(115200);
+
+    while(1) {
+       BAT_MIN = 0;
+       BAT_MAX = 0;   // 0にする
+        ic_set();
+    }
+}
+
+
+
+void ic_set(){
+        
+        //__disable_irq();
+        ic_check();
+        spi_check();
+        spi_error();
+        wakeup();
+        cell_read();
+        
+           }
+
+void ic_check(){  //1
+
+//__disable_irq();
+    pc.baud(115200);
     spi_enable();
     LTC681x_init_cfg(TOTAL_IC, bms_ic);
     LTC6811_reset_crc_count(TOTAL_IC,bms_ic);
     LTC6811_init_reg_limits(TOTAL_IC,bms_ic);
-    print_menu();
+    wakeup_sleep(TOTAL_IC);
+            LTC6811_wrcfg(TOTAL_IC,bms_ic);
+            print_config();
+            //printf("1");
+            //spi_check();
+            
+    }
+    
+void spi_check(){  //2
 
-    while(1) {
-        //pc.printf("check 00\n");
-        //while(!pc.readable()) {
-        wait(0.3);
-        //    pc.printf("check 001\n");
-        //}         // Check for user input
-        //pc.printf("check 01\n");
-        user_command = read_int();      // Read the user commandi
-        pc.printf("command -> %d \n", user_command);
-        run_command(user_command);
-    }
-}
+__disable_irq();
+     int countup;
+    int8_t error = 0;
+    
+     wakeup_sleep(TOTAL_IC);
+            error = LTC6811_rdcfg(TOTAL_IC,bms_ic);
+            check_error(error);
+            print_rxconfig(); 
+            //printf("2");
+            //spi_error();    
+               }
 
-/*!*****************************************
-  \brief executes the user command
-*******************************************/
+
+void wakeup(){  //3
 
-void run_command(uint32_t cmd)
-{
+ __disable_irq();
+    int countup;
     int8_t error = 0;
     uint32_t conv_time = 0;
-//    uint32_t user_command;
-    int8_t readIC=0;
-    char input = 0;
-    switch (cmd) {
-
-        case 1: // Write Configuration Register
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_wrcfg(TOTAL_IC,bms_ic);
-            print_config();
-            break;
-
-        case 2: // Read Configuration Register
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_rdcfg(TOTAL_IC,bms_ic);
-            check_error(error);
-            print_rxconfig();
-            break;
-
-        case 3: // Start Cell ADC Measurement
+                 
+                 
             wakeup_sleep(TOTAL_IC);
             LTC6811_adcv(ADC_CONVERSION_MODE,ADC_DCP,CELL_CH_TO_CONVERT);
             conv_time = LTC6811_pollAdc();
-            pc.printf("cell conversion completed in:");
-            pc.printf("%.1f",((float)conv_time/1000));
-            pc.printf("mS\n");
-            break;
-
-        case 4: // Read Cell Voltage Registers
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_rdcv(0, TOTAL_IC,bms_ic); // Set to read back all cell voltage registers
-            check_error(error);
-            print_cells(DATALOG_DISABLED);
-            break;
-
-        case 5: // Start GPIO ADC Measurement
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_adax(ADC_CONVERSION_MODE , AUX_CH_TO_CONVERT);
-            LTC6811_pollAdc();
-            pc.printf("aux conversion completed\n");
-            pc.printf("\n");
-            break;
-
-        case 6: // Read AUX Voltage Registers
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_rdaux(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
-            check_error(error);
-            print_aux(DATALOG_DISABLED);
-            break;
-
-        case 7: // Start Status ADC Measurement
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_adstat(ADC_CONVERSION_MODE, STAT_CH_TO_CONVERT);
-            LTC6811_pollAdc();
-            pc.printf("stat conversion completed\n");
-            pc.printf("\n");
-            break;
-
-        case 8: // Read Status registers
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_rdstat(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
-            check_error(error);
-            print_stat();
-            break;
+            //printf("3");
+            //cell_read();
+            }
+    
+    
+void spi_error(){
+             
+            //__disable_irq();
+            
+            int8_t error = 0;
+            int countup;
+            /*
+            if(error = -1 ){
+            for(countup = 0; countup <= 2; countup++){
+             spi_check();
+            if(error =1){             
+                 break;
+                        }
+                                                        }                                       
+                           }
+             if(error = 1){
+                   wakeup();
+                          }
+                          */
+                          
+             //wakeup();
+                          
+             
+                 }
+                 
+void cell_read(){  //4  電圧読み取り
 
-        case 9: // Loop Measurements
-            pc.printf("transmit 'm' to quit\n");
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_wrcfg(TOTAL_IC,bms_ic);
-            while (input != 'm') {
-                //if (pc.readable()) {
-                    input = read_char();
-                //}
-
-                measurement_loop(DATALOG_DISABLED);
-
-                wait_ms(MEASUREMENT_LOOP_TIME);
-            }
-            //print_menu();
-            break;
-
-        case 10: // Run open wire self test
-            print_pec();
-
-            break;
-
-        case 11: // Read in raw configuration data
-            LTC6811_reset_crc_count(TOTAL_IC,bms_ic);
-            break;
-
-        case 12:  // Run the ADC/Memory Self Test
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_run_cell_adc_st(CELL,ADC_CONVERSION_MODE,bms_ic);
-            pc.printf("%d", error);
-            pc.printf(" : errors detected in Digital Filter and CELL Memory\n");
-
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_run_cell_adc_st(AUX,ADC_CONVERSION_MODE, bms_ic);
-            pc.printf("%d",error);
-            pc.printf(" : errors detected in Digital Filter and AUX Memory\n");
-
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_run_cell_adc_st(STAT,ADC_CONVERSION_MODE, bms_ic);
-            pc.printf("%d",error);
-            pc.printf(" : errors detected in Digital Filter and STAT Memory\n");
-            print_menu();
-            break;
+ __disable_irq();
+    int8_t error = 0;
+    uint32_t conv_time = 0;
+    int8_t readIC=0;
+    
+         wakeup_sleep(TOTAL_IC);
+            error = LTC6811_rdcv(0, TOTAL_IC,bms_ic); 
+            check_error(error);
+            //print_cells(DATALOG_DISABLED);
+            print_CAN(DATALOG_DISABLED);
+            //printf("4");
+            
+                }           
+            
+    
 
-        case 13: // Enable a discharge transistor
-            pc.printf("Please enter the Spin number\n");
-            readIC = (int8_t)read_int();
-            LTC6811_set_discharge(readIC,TOTAL_IC,bms_ic);
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_wrcfg(TOTAL_IC,bms_ic);
-            print_config();
-            break;
-
-        case 14: // Clear all discharge transistors
-            clear_discharge(TOTAL_IC,bms_ic);
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_wrcfg(TOTAL_IC,bms_ic);
-            print_config();
-            break;
-
-        case 15: // Clear all ADC measurement registers
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_clrcell();
-            LTC6811_clraux();
-            LTC6811_clrstat();
-            pc.printf("All Registers Cleared\n");
-            break;
-
-        case 16: // Run the Mux Decoder Self Test
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_diagn();
-            wait_ms(5);
-            error = LTC6811_rdstat(0,TOTAL_IC,bms_ic); // Set to read back all aux registers
-            check_error(error);
-            error = 0;
-            for (int ic = 0;
-                    ic<TOTAL_IC;
-                    ic++) {
-                if (bms_ic[ic].stat.mux_fail[0] != 0) error++;
+    
+void print_CAN(uint8_t datalog_en){
+    
+    __disable_irq();
+    short n =0;
+    int BAT_SUM = 0; // 0にする
+    int BAT_MIN = 55876;
+    double V,C;
+    int BTA_MAX = 0;
+    float tempC, sum, sum_2, ave, ave_2;
+    int i, j, k, l;   //平均化処理に使用
+    int r = 5;  //平均する値の個数
+     
+    for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) {
+        
+        //if (datalog_en == 0) {
+            //pc.printf("IC%d, ", current_ic+1);
+            //for(n = 0; n <= 12; n++){
+        for (int i=0; i < bms_ic[0].ic_reg.cell_channels; i++) {
+                    
+                    //BAT_CELL[n] = bms_ic[current_ic].cells.c_codes[i];
+                    
+                                                                      
+                     pc.printf("C%d:", i+1);
+                    pc.printf("%.4f, ",bms_ic[current_ic].cells.c_codes[i]*0.0001);
+                     BAT_SUM = bms_ic[current_ic].cells.c_codes[i] +  BAT_SUM;
+                     
+                     if(bms_ic[current_ic].cells.c_codes[i] > 10000){
+                     if(bms_ic[current_ic].cells.c_codes[i] < BAT_MIN){
+                           BAT_MIN = bms_ic[current_ic].cells.c_codes[i];
+                                                                      }
+                                                                      } 
+                                                                                                                     
+                     if( bms_ic[current_ic].cells.c_codes[i] > BAT_MAX){
+                           BAT_MAX = bms_ic[current_ic].cells.c_codes[i];
+                           
+                                                                       }
+                                                                       
+            max.select();                       
+            max_2.deselect_2();
+ 
+          //平均化処理      
+          
+            sum = 0;
+            ave = 0;
+            i = 0;
+           for( i = 0; i < r; i++)            
+             {
+              float temp = max.read_temp();
+              sum += temp;
+             }   
+            
+            ave = sum / r;
+            printf("\n\rT: %f",ave );
+            
+            
+           
+            max.deselect();
+            max_2.select_2();
+             
+        //平均化処理  
+            sum_2 = 0;
+            ave_2 = 0;
+            j = 0;
+           for( j = 0; j < r; j++)            
+           {
+              float temp_2 = max_2.read_temp_2();
+              sum_2 += temp_2;
+           }   
+            
+            ave_2 = sum_2 / r;
+            printf("\n\rT: %f",ave_2 );
+            
+            
+            
+          max.deselect();
+          max_2.deselect_2();
+            
+            
+            
+            max.deselect();
+            max_2.deselect_2();
+                    
+                                                                       
+            
+         
+         //BAT_Current = C;
+                                                                                                                        
+                    
+                                                            
+                                                         
             }
-            if (error==0) pc.printf("Mux Test: PASS\n");
-            else pc.printf("Mux Test: FAIL\n");
-
-            break;
 
-        case 17: // Run ADC Overlap self test
-            wakeup_sleep(TOTAL_IC);
-            error = (int8_t)LTC6811_run_adc_overlap(TOTAL_IC,bms_ic);
-            if (error==0) pc.printf("Overlap Test: PASS\n");
-            else pc.printf("Overlap Test: FAIL\n");
-            break;
-
-        case 18: // Run ADC Redundancy self test
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_run_adc_redundancy_st(ADC_CONVERSION_MODE,AUX,TOTAL_IC, bms_ic);
-            pc.printf("%d",error);
-            pc.printf(" : errors detected in AUX Measurement\n");
-
-            wakeup_sleep(TOTAL_IC);
-            error = LTC6811_run_adc_redundancy_st(ADC_CONVERSION_MODE,STAT,TOTAL_IC, bms_ic);
-            pc.printf("%d",error);
-            pc.printf(" : errors detected in STAT Measurement\n");
-            break;
-
-        case 19:
-            LTC6811_run_openwire(TOTAL_IC, bms_ic);
-            print_open();
-            break;
+        }
+    
+                                                       
+                    pc.printf("\n");
+                    pc.printf("SUM");
+                    pc.printf("%.4f, ",BAT_SUM*0.0001);
+                    BAT_AVG = BAT_SUM / 27;
+                    pc.printf("AVG");
+                    pc.printf("%.4f, ",BAT_AVG*0.0001);
+                    pc.printf("MIN");
+                    pc.printf("%.4f, ",BAT_MIN*0.0001);
+                    pc.printf("MAX");
+                    pc.printf("%.4f, ",BAT_MAX*0.0001);
+                    //pc.printf("BAT_Current");
+                    if((VCmonitor.getVoltage(&V) == 0) && (VCmonitor.getCurrent(&C) == 0)){
+                      printf("V,%f,C,%f\n",V,C);
+            BAT_Current = C;
+            
+                                                                        }
+                    pc.printf("%f, ",BAT_Current);
+                    pc.printf("\n");
+                    pc.printf("\n");
+                    printf("\n\rT: %f",ave );
+                    pc.printf("\n");
+                    printf("\n\rT: %f",ave_2 );
+                    pc.printf("\n");
+                    
+                            if( BAT_MIN < 25000 ){
+                            BAT_MIN_safty = 1 ;
+                            wait(1);
+                            BAT_MIN_safty = 0 ;         
+                                                } 
+                            if( BAT_MAX > 42000){
+                            BAT_MAX_safty = 1;
+                            wait(1);
+                            BAT_MAX_safty = 0;
+                                                         
+                                }
+     }
+     
+    
+/*
+void can_sent4(){
+        
+    if(can1.write(CANMessage(271,&BAT_MAX2))){
+        pc.printf("10CANMessage:%d\n",BAT_MAX2);
+        }
+    if(can1.write(CANMessage(272,&BAT_MAX3))){
+        pc.printf("11CANMessage:%d\n",BAT_MAX3);
+        }
+    if(can1.write(CANMessage(273,&BAT_MAX4))){
+        pc.printf("12CANMessage:%d\n",BAT_MAX4);
+        }
+    
+    }*/
+ /*  
+void can_set(){
+  
+     //NVIC_SetPriority(TIMER3_IRQn, 0);
+     //printf("aaaaa");
+     
+     BAT_SUM1 = 0;
+     BAT_SUM2 = 0;
+     BAT_SUM3 = 0;
+     BAT_SUM4 = 0;
+     BAT_MIN1 = 0;
+     BAT_MIN2 = 0;
+     BAT_MIN3 = 0;
+     BAT_MIN4 = 0;
+     BAT_MAX1 = 0;
+     BAT_MAX2 = 0;
+     BAT_MAX3 = 0;
+     BAT_MAX4 = 0;
+     BAT_Current1 = 0;
+     BAT_Current2 = 0;
+     
+     
+     int data1 = 0;   //BAT_SUM
+     int data2 = 0;
+     int data3 = 0;   //BAT_MAX
+     int data4 = 0;   //BAT_Current
+     
 
-        case 20: //Datalog print option Loop Measurements
-            pc.printf("transmit 'm' to quit\n");
-            wakeup_sleep(TOTAL_IC);
-            LTC6811_wrcfg(TOTAL_IC,bms_ic);
-            while (input != 'm') {
-                //if (pc.readable()) {
-                    input = read_char();
-                //}
-
-                measurement_loop(DATALOG_ENABLED);
-
-                wait_ms(MEASUREMENT_LOOP_TIME);
-            }
-            print_menu();
-            break;
-
-        case 'm': //prints menu
-            print_menu();
-            break;
-
-        default:
-            pc.printf("Incorrect Option\n");
-            break;
+    BAT_SUM = data1;
+    data2 = BAT_MIN;
+    data3 = BAT_MAX;
+    data4 = BAT_Current;
+    
+    BAT_SUM1 = data1 / 1000;  //114
+    BAT_SUM2 = data1 % 1000;   //755
+    BAT_SUM3 = BAT_SUM2 / 10; //75
+    BAT_SUM4 = BAT_SUM2 % 10; // 5
+    
+    BAT_MIN1 = data2 / 1000;   
+    BAT_MIN2 = data2 % 1000;
+    BAT_MIN3 = BAT_MIN2 / 10;
+    BAT_MIN4 = BAT_MIN2 % 10;
+ 
+    BAT_MAX  = data3 / 1000;   
+    BAT_MAX2 = data3 % 1000;
+    BAT_MAX3 = BAT_MAX2 / 10;
+    BAT_MAX4 = BAT_MAX2 % 10;   
+    
+    BAT_Current1 = data4 / 100;
+    BAT_Current2 = data4 % 100;
+    printf("can_set\n");
+    printf("aaaa%f",BAT_SUM);
     }
-}
-
+*/
+            
 void measurement_loop(uint8_t datalog_en)
 {
     int8_t error = 0;
@@ -384,55 +482,33 @@
 }
 
 
-/*!*********************************
-  \brief Prints the main menu
-***********************************/
-void print_menu()
-{
-    pc.printf("Please enter LTC6811 Command\n");
-    pc.printf("Write Configuration: 1            | Reset PEC Counter: 11\n");
-    pc.printf("Read Configuration: 2             | Run ADC Self Test: 12\n");
-    pc.printf("Start Cell Voltage Conversion: 3  | Set Discharge: 13\n");
-    pc.printf("Read Cell Voltages: 4             | Clear Discharge: 14\n");
-    pc.printf("Start Aux Voltage Conversion: 5   | Clear Registers: 15\n");
-    pc.printf("Read Aux Voltages: 6              | Run Mux Self Test: 16\n");
-    pc.printf("Start Stat Voltage Conversion: 7  | Run ADC overlap Test: 17\n");
-    pc.printf("Read Stat Voltages: 8             | Run Digital Redundancy Test: 18\n");
-    pc.printf("loop Measurements: 9              | Run Open Wire Test: 19\n");
-    pc.printf("Read PEC Errors: 10               |  Loop measurements with datalog output: 20\n");
-    pc.printf("\n");
-    pc.printf("Please enter command:\n");
-    pc.printf("\n");
-}
 
-/*!************************************************************
-  \brief Prints cell voltage codes to the serial port
- *************************************************************/
 void print_cells(uint8_t datalog_en)
 {
     for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) {
 
         if (datalog_en == 0) {
             pc.printf("IC%d, ", current_ic+1);
-            for (int i=0; i<bms_ic[0].ic_reg.cell_channels; i++) {
+            for (int i=0; i < bms_ic[0].ic_reg.cell_channels; i++) {
                 pc.printf("C%d:", i+1);
                 pc.printf("%.4f, ", bms_ic[current_ic].cells.c_codes[i]*0.0001);
-            }
+                } 
+                   
             pc.printf("\n");
-        } else {
+            }
+            
+        else {
             pc.printf("Cells, ");
             for (int i=0; i<bms_ic[0].ic_reg.cell_channels; i++) {
-                pc.printf("%.4f, ",bms_ic[current_ic].cells.c_codes[i]*0.0001);
+                pc.printf("%.4f, ",bms_ic[current_ic].cells.c_codes[i]*0.0001);  
+                
             }
         }
-
+        
     }
     pc.printf("\n");
 }
 
-/*!****************************************************************************
-  \brief Prints Open wire test results to the serial port
- *****************************************************************************/
 void print_open()
 {
     for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++) {
@@ -448,9 +524,7 @@
     }
 }
 
-/*!****************************************************************************
-  \brief Prints GPIO voltage codes and Vref2 voltage code onto the serial port
- *****************************************************************************/
+
 void print_aux(uint8_t datalog_en)
 {
 
@@ -471,9 +545,7 @@
     pc.printf("\n");
 }
 
-/*!****************************************************************************
-  \brief Prints Status voltage codes and Vref2 voltage code onto the serial port
- *****************************************************************************/
+
 void print_stat()
 {
 
@@ -488,68 +560,62 @@
     pc.printf("\n");
 }
 
-/*!******************************************************************************
- \brief Prints the configuration data that is going to be written to the LTC6811
- to the serial port.
- ********************************************************************************/
+
 void print_config()
 {
     int cfg_pec;
 
-    pc.printf("Written Configuration: \n");
+    //pc.printf("Written Configuration: \n");
     for (int current_ic = 0; current_ic<TOTAL_IC; current_ic++) {
-        pc.printf(" IC ");
-        pc.printf("%d", current_ic+1);
-        pc.printf(": ");
-        pc.printf("0x");
+        //pc.printf(" IC ");
+        //pc.printf("%d", current_ic+1);
+       // pc.printf(": ");
+        //pc.printf("0x");
         serial_print_hex(bms_ic[current_ic].config.tx_data[0]);
-        pc.printf(", 0x");
+       // pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.tx_data[1]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.tx_data[2]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.tx_data[3]);
-        pc.printf(", 0x");
+       // pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.tx_data[4]);
-        pc.printf(", 0x");
+       // pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.tx_data[5]);
-        pc.printf(", Calculated PEC: 0x");
+        //pc.printf(", Calculated PEC: 0x");
         cfg_pec = pec15_calc(6,&bms_ic[current_ic].config.tx_data[0]);
         serial_print_hex((uint8_t)(cfg_pec>>8));
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex((uint8_t)(cfg_pec));
-        pc.printf("\n");
+       // pc.printf("\n");
     }
-    pc.printf("\n");
+   // pc.printf("\n");
 }
 
-/*!*****************************************************************
- \brief Prints the configuration data that was read back from the
- LTC6811 to the serial port.
- *******************************************************************/
+
 void print_rxconfig()
 {
-    pc.printf("Received Configuration ");
+    //pc.printf("Received Configuration ");
     for (int current_ic=0; current_ic<TOTAL_IC; current_ic++) {
-        pc.printf(" IC ");
-        pc.printf("%d", current_ic+1);
-        pc.printf(": 0x");
+       // pc.printf(" IC ");
+      //  pc.printf("%d", current_ic+1);
+        //pc.printf(": 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[0]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[1]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[2]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[3]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[4]);
-        pc.printf(", 0x");
+       // pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[5]);
-        pc.printf(", Received PEC: 0x");
+        //pc.printf(", Received PEC: 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[6]);
-        pc.printf(", 0x");
+        //pc.printf(", 0x");
         serial_print_hex(bms_ic[current_ic].config.rx_data[7]);
-        pc.printf("\n");
+       // pc.printf("\n");
     }
     pc.printf("\n");
 }
@@ -566,10 +632,12 @@
 
 void serial_print_hex(uint8_t data)
 {
+    /*
     if (data < 16) {
-        pc.printf("0x0%X", data);
+        //pc.printf("0x0%X", data);
     } else
-        pc.printf("0x%X", data);
+       pc.printf("0x%X", data);
+       */
 }
 
 //Function to check error flag and print PEC error message
@@ -581,12 +649,12 @@
 }
 
 
-// hex conversion constants
+
 char hex_digits[16]= {
     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
 };
 
-// global variables
+
 
 char hex_to_byte_buffer[5]= {
     '0', 'x', '0', '0', '\0'
@@ -595,46 +663,46 @@
     '\0','\0','\0'
 };
 
-// Read data from the serial interface into the ui_buffer
+// シリアル インターフェイスから ui_バッファへのデータの読み取り
 uint8_t read_data()
 {
-    uint8_t index = 0; //index to hold current location in ui_buffer
-    int c; // single character used to store incoming keystrokes
+    uint8_t index = 0; // 内の現在の場所を保持するインデックス
+    int c; // 着信キーストロークの格納に使用される単一の文字
     //pc.printf("check 1\n");
     while (index < UI_BUFFER_SIZE-1) {
         //pc.printf("check 2\n");
-        c = pc.getc(); //read one character
+        c = pc.getc(); 
         //return c;
         //pc.printf("check 3\n");
         
-        if (((char) c == '\r') || ((char) c == '\n')) break; // if carriage return or linefeed, stop and return data
-        if ( ((char) c == '\x7F') || ((char) c == '\x08') ) { // remove previous character (decrement index) if Backspace/Delete key pressed      index--;
+        if (((char) c == '\r') || ((char) c == '\n')) break; 
+        if ( ((char) c == '\x7F') || ((char) c == '\x08') ) { 
             if (index > 0) index--;
         } else if (c >= 0) {
-            ui_buffer[index++]=(char) c; // put character into ui_buffer
+            ui_buffer[index++]=(char) c; 
         }
         //pc.printf("check 4\n");
         
     }
-    ui_buffer[index]='\0';  // terminate string with NULL
+    ui_buffer[index]='\0';  
 
-    if ((char) c == '\r') {  // if the "last" character was a carriage return, also clear linefeed if it is next character
+    if ((char) c == '\r') {  
         wait_ms(1);
         //pc.printf("check 5\n");
         
         if (pc.readable()==1) {
             //pc.printf("check 6\n");
-            pc.getc(); // if linefeed appears, read it and throw it away
+            pc.getc(); 
         }
-        //pc.printf("check 7\n");
+        
         
     }
-    //pc.printf("check 8\n");
+    
         
-    return index; // return number of characters, not including null terminator
+    return index; 
 }
 
-// Read a float value from the serial interface
+
 float read_float()
 {
     float data;
@@ -643,13 +711,7 @@
     return(data);
 }
 
-// Read an integer from the serial interface.
-// The routine can recognize Hex, Decimal, Octal, or Binary
-// Example:
-// Hex:     0x11 (0x prefix)
-// Decimal: 17
-// Octal:   021 (leading zero prefix)
-// Binary:  B10001 (leading B prefix)
+
 int32_t read_int()
 {
     int32_t data;
@@ -663,14 +725,13 @@
     return(data);
 }
 
-// Read a string from the serial interface.  Returns a pointer to the ui_buffer.
 char *read_string()
 {
     read_data();
     return(ui_buffer);
 }
 
-// Read a character from the serial interface
+
 int8_t read_char()
 {
     read_data();