![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
all bms comunicating with nucleo board and balancing
Dependencies: CANnucleo LTC68041 mbed
Fork of BMS_2 by
Diff: main.cpp
- Revision:
- 25:6f4f7510db24
- Parent:
- 24:f47f1fd6ce01
- Child:
- 26:c55656391a29
diff -r f47f1fd6ce01 -r 6f4f7510db24 main.cpp --- a/main.cpp Sat Oct 22 19:05:26 2016 +0000 +++ b/main.cpp Mon Oct 24 13:10:45 2016 +0000 @@ -91,6 +91,7 @@ serial_print_hex(rx_cfg[current_ic][7]); } } + int err; void print_cells2() { @@ -107,6 +108,7 @@ } } + void pec_error() { for(int i = 0; i<5; i++) { @@ -116,6 +118,7 @@ wait(0.2); } } + char cells_left=0; Ticker ticker; Ticker sender; @@ -131,11 +134,8 @@ if(cells_left < 1) { sender.detach(); } else { - - to_send = 1; } - } void check_charging_voltage() @@ -154,29 +154,52 @@ } for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { for (int i=0; i<12; i++) { - if(cell_codes[current_ic][i]*0.0001 > 3.85) { + if(cell_codes[current_ic][i]*0.0001 > 3.6) { switch (i) { case 0: - tx_cfg[0][4] = tx_cfg[0][4] | 0x01 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x01 ; // 00000001 case 1: - tx_cfg[0][4] = tx_cfg[0][4] | 0x02 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x02 ; // 00000010 case 2: - tx_cfg[0][4] = tx_cfg[0][4] | 0x04 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x04 ; // 00000100 case 3: - tx_cfg[0][4] = tx_cfg[0][4] | 0x08 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x08 ; // 00001000 case 4: - tx_cfg[0][4] = tx_cfg[0][4] | 0x10 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x10 ; // 00010000 case 5: - tx_cfg[0][4] = tx_cfg[0][4] | 0x20 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x20 ; // 00100001 case 6: - tx_cfg[0][4] = tx_cfg[0][4] | 0x40 ; + tx_cfg[0][4] = tx_cfg[0][4] | 0x40 ; // 01000001 case 7: - tx_cfg[0][4] = tx_cfg[0][4] | 0x80; + tx_cfg[0][4] = tx_cfg[0][4] | 0x80; // 10000001 case 8: - tx_cfg[0][5] = tx_cfg[0][5] | 0x01; + tx_cfg[0][5] = tx_cfg[0][5] | 0x01; // 00000001 case 9: - tx_cfg[0][5] = tx_cfg[0][5] | 0x10; - } + tx_cfg[0][5] = tx_cfg[0][5] | 0x10; // 00000010 + } + }else{ + switch (i){ + case 0: + tx_cfg[0][4] = tx_cfg[0][4] & 0xFE ; // 11111110 + case 1: + tx_cfg[0][4] = tx_cfg[0][4] & 0xFD ; // 11111101 + case 2: + tx_cfg[0][4] = tx_cfg[0][4] & 0xFB ; // 11111011 + case 3: + tx_cfg[0][4] = tx_cfg[0][4] & 0xF7 ; // 11110111 + case 4: + tx_cfg[0][4] = tx_cfg[0][4] & 0xEF ; // 11101111 + case 5: + tx_cfg[0][4] = tx_cfg[0][4] & 0xDF ; // 11011111 + case 6: + tx_cfg[0][4] = tx_cfg[0][4] & 0xBF ; // 10111111 + case 7: + tx_cfg[0][4] = tx_cfg[0][4] & 0x7F; // 01111111 + case 8: + tx_cfg[0][5] = tx_cfg[0][5] & 0xFE; // 11111110 + case 9: + tx_cfg[0][5] = tx_cfg[0][5] & 0xFD; // 11111101 + } } } } @@ -226,10 +249,10 @@ } - -bool to_charge_or_not_to_charge=false; // false = discharge +bool to_charge_or_not_to_charge=true; // false = discharge bool charging = false; bool discharging = false; + void monitor() { led = !led; @@ -303,7 +326,7 @@ to_send=0; txMsg.clear(); - txMsg.id = 13; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. + txMsg.id = 11; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. txMsg.len = 5; data.f[0] = cell_codes[0][cells_left-1]*0.0001; txMsg.data[0] = data.bytes[0];