![](/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
main.cpp@23:bde0179eee92, 2016-10-22 (annotated)
- Committer:
- Crazyaboutmachines
- Date:
- Sat Oct 22 17:41:59 2016 +0000
- Revision:
- 23:bde0179eee92
- Parent:
- 21:988413f53fbe
- Child:
- 24:f47f1fd6ce01
import state
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 19:872e304d7e17 | 1 | #include "CANnucleo.h" |
hudakz | 16:a86f339d1c25 | 2 | #include "mbed.h" |
ser1516 | 21:988413f53fbe | 3 | #include "LTC68041.h" |
hudakz | 16:a86f339d1c25 | 4 | |
ser1516 | 21:988413f53fbe | 5 | |
ser1516 | 21:988413f53fbe | 6 | |
ser1516 | 21:988413f53fbe | 7 | uint8_t const TOTAL_IC = 1;//!<number of ICs in the daisy chain |
ser1516 | 21:988413f53fbe | 8 | |
ser1516 | 21:988413f53fbe | 9 | uint8_t rx_cfg[TOTAL_IC][8]; |
ser1516 | 21:988413f53fbe | 10 | uint8_t tx_cfg[TOTAL_IC][6]; |
ser1516 | 21:988413f53fbe | 11 | uint16_t aux_codes[TOTAL_IC][6]; |
ser1516 | 21:988413f53fbe | 12 | uint16_t cell_codes[TOTAL_IC][12]; |
ser1516 | 21:988413f53fbe | 13 | volatile bool msgAvailable = false; |
ser1516 | 21:988413f53fbe | 14 | volatile bool to_send = false; |
hudakz | 17:18d4d0ff26a6 | 15 | CANnucleo::CAN can(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name |
hudakz | 17:18d4d0ff26a6 | 16 | CANnucleo::CANMessage rxMsg; |
hudakz | 17:18d4d0ff26a6 | 17 | CANnucleo::CANMessage txMsg; |
ser1516 | 21:988413f53fbe | 18 | DigitalOut led(PA_5); |
ser1516 | 21:988413f53fbe | 19 | /*!*********************************** |
ser1516 | 21:988413f53fbe | 20 | \brief Initializes the configuration array |
ser1516 | 21:988413f53fbe | 21 | **************************************/ |
ser1516 | 21:988413f53fbe | 22 | void init_cfg() |
ser1516 | 21:988413f53fbe | 23 | { |
ser1516 | 21:988413f53fbe | 24 | for (int i = 0; i<TOTAL_IC; i++) { |
ser1516 | 21:988413f53fbe | 25 | tx_cfg[i][0] = 0xFE; |
ser1516 | 21:988413f53fbe | 26 | tx_cfg[i][1] = 0x00 ; |
ser1516 | 21:988413f53fbe | 27 | tx_cfg[i][2] = 0x00 ; |
ser1516 | 21:988413f53fbe | 28 | tx_cfg[i][3] = 0x00 ; |
ser1516 | 21:988413f53fbe | 29 | tx_cfg[i][4] = 0x00 ; |
ser1516 | 21:988413f53fbe | 30 | tx_cfg[i][5] = 0x00 ; |
ser1516 | 21:988413f53fbe | 31 | } |
ser1516 | 21:988413f53fbe | 32 | } |
ser1516 | 21:988413f53fbe | 33 | void serial_print_hex(uint8_t data) |
ser1516 | 21:988413f53fbe | 34 | { |
ser1516 | 21:988413f53fbe | 35 | if (data< 16) { |
ser1516 | 21:988413f53fbe | 36 | printf("0"); |
ser1516 | 21:988413f53fbe | 37 | printf("%x",(uint8_t)data); |
ser1516 | 21:988413f53fbe | 38 | } else |
ser1516 | 21:988413f53fbe | 39 | printf("%x",(uint8_t)data); |
ser1516 | 21:988413f53fbe | 40 | } |
ser1516 | 21:988413f53fbe | 41 | void print_config() |
ser1516 | 21:988413f53fbe | 42 | { |
ser1516 | 21:988413f53fbe | 43 | int cfg_pec; |
ser1516 | 21:988413f53fbe | 44 | printf("Written Configuration:\n\r "); |
ser1516 | 21:988413f53fbe | 45 | for (int current_ic = 0; current_ic<TOTAL_IC; current_ic++) { |
ser1516 | 21:988413f53fbe | 46 | printf(" IC "); |
ser1516 | 21:988413f53fbe | 47 | printf("%d", current_ic+1); |
ser1516 | 21:988413f53fbe | 48 | printf(": "); |
ser1516 | 21:988413f53fbe | 49 | printf("0x"); |
ser1516 | 21:988413f53fbe | 50 | serial_print_hex(tx_cfg[current_ic][0]); |
ser1516 | 21:988413f53fbe | 51 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 52 | serial_print_hex(tx_cfg[current_ic][1]); |
ser1516 | 21:988413f53fbe | 53 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 54 | serial_print_hex(tx_cfg[current_ic][2]); |
ser1516 | 21:988413f53fbe | 55 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 56 | serial_print_hex(tx_cfg[current_ic][3]); |
ser1516 | 21:988413f53fbe | 57 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 58 | serial_print_hex(tx_cfg[current_ic][4]); |
ser1516 | 21:988413f53fbe | 59 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 60 | serial_print_hex(tx_cfg[current_ic][5]); |
ser1516 | 21:988413f53fbe | 61 | printf(", Calculated PEC: 0x"); |
ser1516 | 21:988413f53fbe | 62 | cfg_pec = pec15_calc(6,&tx_cfg[current_ic][0]); |
ser1516 | 21:988413f53fbe | 63 | serial_print_hex((uint8_t)(cfg_pec>>8)); |
ser1516 | 21:988413f53fbe | 64 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 65 | serial_print_hex((uint8_t)(cfg_pec)); |
ser1516 | 21:988413f53fbe | 66 | } |
ser1516 | 21:988413f53fbe | 67 | printf("\n\r"); |
ser1516 | 21:988413f53fbe | 68 | } |
ser1516 | 21:988413f53fbe | 69 | |
ser1516 | 21:988413f53fbe | 70 | void print_rxconfig() |
ser1516 | 21:988413f53fbe | 71 | { |
ser1516 | 21:988413f53fbe | 72 | printf("Received Configuration "); |
ser1516 | 21:988413f53fbe | 73 | for (int current_ic=0; current_ic<TOTAL_IC; current_ic++) { |
ser1516 | 21:988413f53fbe | 74 | printf(" IC "); |
ser1516 | 21:988413f53fbe | 75 | printf("%d " ,current_ic+1); |
ser1516 | 21:988413f53fbe | 76 | printf(": 0x"); |
ser1516 | 21:988413f53fbe | 77 | serial_print_hex(rx_cfg[current_ic][0]); |
ser1516 | 21:988413f53fbe | 78 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 79 | serial_print_hex(rx_cfg[current_ic][1]); |
ser1516 | 21:988413f53fbe | 80 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 81 | serial_print_hex(rx_cfg[current_ic][2]); |
ser1516 | 21:988413f53fbe | 82 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 83 | serial_print_hex(rx_cfg[current_ic][3]); |
ser1516 | 21:988413f53fbe | 84 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 85 | serial_print_hex(rx_cfg[current_ic][4]); |
ser1516 | 21:988413f53fbe | 86 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 87 | serial_print_hex(rx_cfg[current_ic][5]); |
ser1516 | 21:988413f53fbe | 88 | printf(", Received PEC: 0x"); |
ser1516 | 21:988413f53fbe | 89 | serial_print_hex(rx_cfg[current_ic][6]); |
ser1516 | 21:988413f53fbe | 90 | printf(", 0x"); |
ser1516 | 21:988413f53fbe | 91 | serial_print_hex(rx_cfg[current_ic][7]); |
ser1516 | 21:988413f53fbe | 92 | } |
ser1516 | 21:988413f53fbe | 93 | } |
ser1516 | 21:988413f53fbe | 94 | int err; |
ser1516 | 21:988413f53fbe | 95 | void print_cells2() |
ser1516 | 21:988413f53fbe | 96 | { |
ser1516 | 21:988413f53fbe | 97 | |
ser1516 | 21:988413f53fbe | 98 | for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { |
ser1516 | 21:988413f53fbe | 99 | |
ser1516 | 21:988413f53fbe | 100 | for (int i=0; i<12; i++) { |
ser1516 | 21:988413f53fbe | 101 | printf(" C"); |
ser1516 | 21:988413f53fbe | 102 | printf("%d",i+1); |
ser1516 | 21:988413f53fbe | 103 | printf(":"); |
ser1516 | 21:988413f53fbe | 104 | printf("%f", cell_codes[current_ic][i]*0.0001); |
ser1516 | 21:988413f53fbe | 105 | printf(","); |
ser1516 | 21:988413f53fbe | 106 | } |
hudakz | 0:c5e5d0df6f2a | 107 | |
ser1516 | 21:988413f53fbe | 108 | } |
ser1516 | 21:988413f53fbe | 109 | } |
ser1516 | 21:988413f53fbe | 110 | void pec_error() |
ser1516 | 21:988413f53fbe | 111 | { |
ser1516 | 21:988413f53fbe | 112 | for(int i = 0; i<5; i++) { |
ser1516 | 21:988413f53fbe | 113 | led = 1; |
ser1516 | 21:988413f53fbe | 114 | wait(0.2); |
ser1516 | 21:988413f53fbe | 115 | led=0; |
ser1516 | 21:988413f53fbe | 116 | wait(0.2); |
ser1516 | 21:988413f53fbe | 117 | } |
ser1516 | 21:988413f53fbe | 118 | } |
ser1516 | 21:988413f53fbe | 119 | char cells_left=0; |
ser1516 | 21:988413f53fbe | 120 | Ticker ticker; |
ser1516 | 21:988413f53fbe | 121 | Ticker sender; |
ser1516 | 21:988413f53fbe | 122 | |
ser1516 | 21:988413f53fbe | 123 | typedef union can_union { |
ser1516 | 21:988413f53fbe | 124 | int i[2]; |
ser1516 | 21:988413f53fbe | 125 | char bytes[8]; |
ser1516 | 21:988413f53fbe | 126 | float f[2]; |
ser1516 | 21:988413f53fbe | 127 | } data; |
ser1516 | 21:988413f53fbe | 128 | |
ser1516 | 21:988413f53fbe | 129 | void message_trigger() |
ser1516 | 21:988413f53fbe | 130 | { |
ser1516 | 21:988413f53fbe | 131 | if(cells_left < 1) { |
ser1516 | 21:988413f53fbe | 132 | sender.detach(); |
ser1516 | 21:988413f53fbe | 133 | } else { |
ser1516 | 21:988413f53fbe | 134 | |
ser1516 | 21:988413f53fbe | 135 | |
ser1516 | 21:988413f53fbe | 136 | to_send = 1; |
ser1516 | 21:988413f53fbe | 137 | } |
ser1516 | 21:988413f53fbe | 138 | |
ser1516 | 21:988413f53fbe | 139 | } |
ser1516 | 21:988413f53fbe | 140 | |
ser1516 | 21:988413f53fbe | 141 | void check_charging_voltage() |
ser1516 | 21:988413f53fbe | 142 | { |
ser1516 | 21:988413f53fbe | 143 | wakeup_idle(); |
ser1516 | 21:988413f53fbe | 144 | __disable_irq(); |
ser1516 | 21:988413f53fbe | 145 | LTC6804_adcv(); |
ser1516 | 21:988413f53fbe | 146 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 147 | wait_ms(10); |
ser1516 | 21:988413f53fbe | 148 | wakeup_idle(); |
ser1516 | 21:988413f53fbe | 149 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 150 | err = LTC6804_rdcv(0, TOTAL_IC,cell_codes); |
ser1516 | 21:988413f53fbe | 151 | __disable_irq(); |
ser1516 | 21:988413f53fbe | 152 | if (err == -1) { |
ser1516 | 21:988413f53fbe | 153 | pec_error(); |
ser1516 | 21:988413f53fbe | 154 | } |
ser1516 | 21:988413f53fbe | 155 | for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { |
ser1516 | 21:988413f53fbe | 156 | for (int i=0; i<12; i++) { |
ser1516 | 21:988413f53fbe | 157 | if(cell_codes[current_ic][i]*0.0001 > 3.85) { |
ser1516 | 21:988413f53fbe | 158 | switch (i) { |
ser1516 | 21:988413f53fbe | 159 | case 0: |
ser1516 | 21:988413f53fbe | 160 | tx_cfg[0][4] = tx_cfg[0][4] | 0x01 ; |
ser1516 | 21:988413f53fbe | 161 | case 1: |
ser1516 | 21:988413f53fbe | 162 | tx_cfg[0][4] = tx_cfg[0][4] | 0x02 ; |
ser1516 | 21:988413f53fbe | 163 | case 2: |
ser1516 | 21:988413f53fbe | 164 | tx_cfg[0][4] = tx_cfg[0][4] | 0x04 ; |
ser1516 | 21:988413f53fbe | 165 | case 3: |
ser1516 | 21:988413f53fbe | 166 | tx_cfg[0][4] = tx_cfg[0][4] | 0x08 ; |
ser1516 | 21:988413f53fbe | 167 | case 4: |
ser1516 | 21:988413f53fbe | 168 | tx_cfg[0][4] = tx_cfg[0][4] | 0x10 ; |
ser1516 | 21:988413f53fbe | 169 | case 5: |
ser1516 | 21:988413f53fbe | 170 | tx_cfg[0][4] = tx_cfg[0][4] | 0x20 ; |
ser1516 | 21:988413f53fbe | 171 | case 6: |
ser1516 | 21:988413f53fbe | 172 | tx_cfg[0][4] = tx_cfg[0][4] | 0x40 ; |
ser1516 | 21:988413f53fbe | 173 | case 7: |
ser1516 | 21:988413f53fbe | 174 | tx_cfg[0][4] = tx_cfg[0][4] | 0x80; |
ser1516 | 21:988413f53fbe | 175 | case 8: |
ser1516 | 21:988413f53fbe | 176 | tx_cfg[0][5] = tx_cfg[0][5] | 0x01; |
ser1516 | 21:988413f53fbe | 177 | case 9: |
ser1516 | 21:988413f53fbe | 178 | tx_cfg[0][5] = tx_cfg[0][5] | 0x10; |
ser1516 | 21:988413f53fbe | 179 | } |
ser1516 | 21:988413f53fbe | 180 | } |
ser1516 | 21:988413f53fbe | 181 | } |
ser1516 | 21:988413f53fbe | 182 | } |
ser1516 | 21:988413f53fbe | 183 | //print_cells2(); |
ser1516 | 21:988413f53fbe | 184 | __disable_irq(); |
ser1516 | 21:988413f53fbe | 185 | LTC6804_wrcfg(TOTAL_IC,tx_cfg); |
ser1516 | 21:988413f53fbe | 186 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 187 | } |
ser1516 | 21:988413f53fbe | 188 | |
ser1516 | 21:988413f53fbe | 189 | |
ser1516 | 21:988413f53fbe | 190 | |
ser1516 | 21:988413f53fbe | 191 | void check_discharging_voltage() |
ser1516 | 21:988413f53fbe | 192 | { |
ser1516 | 21:988413f53fbe | 193 | wakeup_idle(); |
ser1516 | 21:988413f53fbe | 194 | LTC6804_adcv(); |
ser1516 | 21:988413f53fbe | 195 | |
ser1516 | 21:988413f53fbe | 196 | wait_ms(10); |
ser1516 | 21:988413f53fbe | 197 | wakeup_idle(); |
ser1516 | 21:988413f53fbe | 198 | err = LTC6804_rdcv(0, TOTAL_IC,cell_codes); |
ser1516 | 21:988413f53fbe | 199 | if (err == -1) { |
ser1516 | 21:988413f53fbe | 200 | pec_error(); |
ser1516 | 21:988413f53fbe | 201 | }/* |
ser1516 | 21:988413f53fbe | 202 | for (int current_ic = 0 ; current_ic < TOTAL_IC; current_ic++) { |
ser1516 | 21:988413f53fbe | 203 | for (int i=0; i<11; i++) { |
ser1516 | 21:988413f53fbe | 204 | //printf("%f\t", cell_codes[current_ic][i]*0.0001); |
ser1516 | 21:988413f53fbe | 205 | if(cell_codes[current_ic][i]*0.0001 < 2.7) { |
ser1516 | 21:988413f53fbe | 206 | txMsg.clear(); |
ser1516 | 21:988413f53fbe | 207 | txMsg.id = 1; |
ser1516 | 21:988413f53fbe | 208 | printf("%f\t", cell_codes[current_ic][i]*0.0001); |
ser1516 | 21:988413f53fbe | 209 | |
ser1516 | 21:988413f53fbe | 210 | txMsg << cell_codes[current_ic][i]*0.0001; |
ser1516 | 21:988413f53fbe | 211 | can.write(txMsg); |
ser1516 | 21:988413f53fbe | 212 | wait(0.1); |
ser1516 | 21:988413f53fbe | 213 | } |
ser1516 | 21:988413f53fbe | 214 | } |
ser1516 | 21:988413f53fbe | 215 | }*/ |
ser1516 | 21:988413f53fbe | 216 | //print_cells2(); |
ser1516 | 21:988413f53fbe | 217 | cells_left = 12; |
ser1516 | 21:988413f53fbe | 218 | |
ser1516 | 21:988413f53fbe | 219 | //print_cells2(); |
ser1516 | 21:988413f53fbe | 220 | LTC6804_wrcfg(TOTAL_IC,tx_cfg); |
ser1516 | 21:988413f53fbe | 221 | } |
ser1516 | 21:988413f53fbe | 222 | |
ser1516 | 21:988413f53fbe | 223 | void onMsgReceived() |
ser1516 | 21:988413f53fbe | 224 | { |
hudakz | 16:a86f339d1c25 | 225 | msgAvailable = true; |
hudakz | 16:a86f339d1c25 | 226 | } |
hudakz | 16:a86f339d1c25 | 227 | |
ser1516 | 21:988413f53fbe | 228 | |
hudakz | 0:c5e5d0df6f2a | 229 | |
ser1516 | 21:988413f53fbe | 230 | bool to_charge_or_not_to_charge=false; // false = discharge |
ser1516 | 21:988413f53fbe | 231 | bool charging = false; |
ser1516 | 21:988413f53fbe | 232 | bool discharging = false; |
ser1516 | 21:988413f53fbe | 233 | void monitor() |
ser1516 | 21:988413f53fbe | 234 | { |
ser1516 | 21:988413f53fbe | 235 | led = !led; |
ser1516 | 21:988413f53fbe | 236 | if(to_charge_or_not_to_charge) { |
ser1516 | 21:988413f53fbe | 237 | charging = 1; |
ser1516 | 21:988413f53fbe | 238 | discharging = 0; |
ser1516 | 21:988413f53fbe | 239 | } else { |
ser1516 | 21:988413f53fbe | 240 | discharging = 1; |
ser1516 | 21:988413f53fbe | 241 | charging = 0; |
hudakz | 0:c5e5d0df6f2a | 242 | } |
hudakz | 0:c5e5d0df6f2a | 243 | } |
hudakz | 7:2dce8ed51091 | 244 | |
hudakz | 12:e91e44924194 | 245 | |
ser1516 | 21:988413f53fbe | 246 | int main() |
ser1516 | 21:988413f53fbe | 247 | { |
ser1516 | 21:988413f53fbe | 248 | data data; |
hudakz | 17:18d4d0ff26a6 | 249 | |
ser1516 | 21:988413f53fbe | 250 | //printf("starting\n\r"); |
ser1516 | 21:988413f53fbe | 251 | led =1; |
ser1516 | 21:988413f53fbe | 252 | wait(1); |
ser1516 | 21:988413f53fbe | 253 | pec_error(); |
ser1516 | 21:988413f53fbe | 254 | discharging = 1; |
ser1516 | 21:988413f53fbe | 255 | |
ser1516 | 21:988413f53fbe | 256 | ticker.attach(&monitor, 5); |
ser1516 | 21:988413f53fbe | 257 | LTC6804_initialize(); |
ser1516 | 21:988413f53fbe | 258 | init_cfg(); |
ser1516 | 21:988413f53fbe | 259 | //write configuration |
ser1516 | 21:988413f53fbe | 260 | wakeup_sleep(); |
ser1516 | 21:988413f53fbe | 261 | __disable_irq(); // Disable Interrupts |
ser1516 | 21:988413f53fbe | 262 | LTC6804_wrcfg(TOTAL_IC,tx_cfg); |
ser1516 | 21:988413f53fbe | 263 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 264 | wait(1); |
ser1516 | 21:988413f53fbe | 265 | //read configuration: may differ from written config |
ser1516 | 21:988413f53fbe | 266 | wakeup_sleep(); |
ser1516 | 21:988413f53fbe | 267 | __disable_irq(); |
ser1516 | 21:988413f53fbe | 268 | err = LTC6804_rdcfg(TOTAL_IC,rx_cfg); |
ser1516 | 21:988413f53fbe | 269 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 270 | if (err == -1) { |
ser1516 | 21:988413f53fbe | 271 | pec_error(); |
ser1516 | 21:988413f53fbe | 272 | } |
ser1516 | 21:988413f53fbe | 273 | wait(0.5); |
ser1516 | 21:988413f53fbe | 274 | |
ser1516 | 21:988413f53fbe | 275 | wakeup_idle(); |
ser1516 | 21:988413f53fbe | 276 | __disable_irq(); |
ser1516 | 21:988413f53fbe | 277 | LTC6804_adcv(); |
ser1516 | 21:988413f53fbe | 278 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 279 | wait_ms(10); |
ser1516 | 21:988413f53fbe | 280 | wakeup_idle(); |
ser1516 | 21:988413f53fbe | 281 | __disable_irq(); |
ser1516 | 21:988413f53fbe | 282 | err = LTC6804_rdcv(0, TOTAL_IC,cell_codes); |
ser1516 | 21:988413f53fbe | 283 | __enable_irq(); |
ser1516 | 21:988413f53fbe | 284 | if (err == -1) { |
ser1516 | 21:988413f53fbe | 285 | pec_error(); |
ser1516 | 21:988413f53fbe | 286 | } |
ser1516 | 21:988413f53fbe | 287 | can.frequency(1000000); // set bit rate to 1Mbps |
ser1516 | 21:988413f53fbe | 288 | can.attach(&onMsgReceived); |
ser1516 | 21:988413f53fbe | 289 | //print_cells2(); |
ser1516 | 21:988413f53fbe | 290 | while(1) { |
ser1516 | 21:988413f53fbe | 291 | if(charging) { |
ser1516 | 21:988413f53fbe | 292 | charging = 0; |
ser1516 | 21:988413f53fbe | 293 | check_charging_voltage(); |
ser1516 | 21:988413f53fbe | 294 | |
ser1516 | 21:988413f53fbe | 295 | } |
ser1516 | 21:988413f53fbe | 296 | if(discharging) { |
ser1516 | 21:988413f53fbe | 297 | discharging = 0; |
ser1516 | 21:988413f53fbe | 298 | check_discharging_voltage(); |
ser1516 | 21:988413f53fbe | 299 | sender.attach(&message_trigger,0.1); |
ser1516 | 21:988413f53fbe | 300 | } |
ser1516 | 21:988413f53fbe | 301 | if(to_send) { |
ser1516 | 21:988413f53fbe | 302 | |
ser1516 | 21:988413f53fbe | 303 | |
ser1516 | 21:988413f53fbe | 304 | to_send=0; |
ser1516 | 21:988413f53fbe | 305 | txMsg.clear(); |
Crazyaboutmachines | 23:bde0179eee92 | 306 | txMsg.id = 11; |
ser1516 | 21:988413f53fbe | 307 | txMsg.len = 5; |
ser1516 | 21:988413f53fbe | 308 | data.f[0] = cell_codes[0][cells_left-1]*0.0001; |
ser1516 | 21:988413f53fbe | 309 | txMsg.data[0] = data.bytes[0]; |
ser1516 | 21:988413f53fbe | 310 | txMsg.data[1] = data.bytes[1]; |
ser1516 | 21:988413f53fbe | 311 | txMsg.data[2] = data.bytes[2]; |
ser1516 | 21:988413f53fbe | 312 | txMsg.data[3] = data.bytes[3]; |
ser1516 | 21:988413f53fbe | 313 | txMsg.data[4] = cells_left; |
ser1516 | 21:988413f53fbe | 314 | cells_left--; |
Crazyaboutmachines | 23:bde0179eee92 | 315 | if(!(can.write(txMsg))) { //se nao conseguiu transmitir continua a tentar transmitir a tensão dessa celula |
ser1516 | 21:988413f53fbe | 316 | pec_error(); |
ser1516 | 21:988413f53fbe | 317 | cells_left++; |
ser1516 | 21:988413f53fbe | 318 | //to_send=1; |
ser1516 | 21:988413f53fbe | 319 | } |
ser1516 | 21:988413f53fbe | 320 | |
ser1516 | 21:988413f53fbe | 321 | } |
ser1516 | 21:988413f53fbe | 322 | } |
ser1516 | 21:988413f53fbe | 323 | |
ser1516 | 21:988413f53fbe | 324 | } |