Ultima versão da banca de ensaios ECU Fev2017

Dependencies:   CANnucleo mbed

Fork of Can_sniffer_BMS4 by Gerardo Antonio

Committer:
Crazyaboutmachines
Date:
Wed Nov 09 10:14:03 2016 +0000
Revision:
36:00ea3ae2cead
Parent:
35:a8940aaa101f
Child:
37:1e1f3131fef5
lee tensoes erradas

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:c5e5d0df6f2a 1 /*
hudakz 16:a86f339d1c25 2 * An example showing how to use the CANnucleo library:
hudakz 0:c5e5d0df6f2a 3 *
ser1516 21:13ac27349025 4 * Two affordable (less than $3 on ebay) STM32F103C8T6 boards (20kB SRAM, 64kB Flash),
ser1516 21:13ac27349025 5 * (see [https://developer.mbed.org/users/hudakz/code/STM32F103C8T6_Hello/] for more details)
ser1516 21:13ac27349025 6 * are connected to the same CAN bus via transceivers (MCP2551 or TJA1040, or etc.).
ser1516 21:13ac27349025 7 * CAN transceivers are not part of NUCLEO boards, therefore must be added by you.
hudakz 6:7ff95ce72f6d 8 * Remember also that CAN bus (even a short one) must be terminated with 120 Ohm resitors at both ends.
hudakz 6:7ff95ce72f6d 9 *
hudakz 16:a86f339d1c25 10 * For more details see the wiki page <https://developer.mbed.org/users/hudakz/code/CANnucleo_Hello/>
hudakz 6:7ff95ce72f6d 11 *
hudakz 17:18d4d0ff26a6 12 * NOTE: If you'd like to use the official NUCLEO boards comment out line 22
hudakz 6:7ff95ce72f6d 13 *
hudakz 6:7ff95ce72f6d 14 * The same code is used for both NUCLEO boards, but:
hudakz 0:c5e5d0df6f2a 15 * For board #1 compile the example without any change.
ser1516 21:13ac27349025 16 * For board #2 comment out line 23 before compiling
hudakz 4:ccf4ac2deac8 17 *
hudakz 6:7ff95ce72f6d 18 * Once the binaries have been downloaded to the boards reset board #1.
hudakz 0:c5e5d0df6f2a 19 *
ser1516 21:13ac27349025 20 */
hudakz 0:c5e5d0df6f2a 21
ser1516 21:13ac27349025 22 //#define TARGET_STM32F103C8T6 1 // uncomment this line when using STM32F103C8T6 boards!
ser1516 21:13ac27349025 23 //#define BOARD1 1 // comment out this line when compiling for board #2
hudakz 0:c5e5d0df6f2a 24
ser1516 21:13ac27349025 25
Crazyaboutmachines 29:3af76325f86a 26
Crazyaboutmachines 26:3ac15dfbb66b 27 //CAN devices IDs and reserved ID's-----------------------------------
Crazyaboutmachines 23:1a29761becd2 28 //ID|Device
Crazyaboutmachines 26:3ac15dfbb66b 29 //9|ECU|Key switch
Crazyaboutmachines 26:3ac15dfbb66b 30 //10|ECU|Charge/discharge
Crazyaboutmachines 26:3ac15dfbb66b 31 //11|BMS1|Cell voltages
Crazyaboutmachines 26:3ac15dfbb66b 32 //12|BMS2|Cell voltages
Crazyaboutmachines 26:3ac15dfbb66b 33 //13|BMS3|Cell voltages
Crazyaboutmachines 26:3ac15dfbb66b 34 //?|Charger|
Crazyaboutmachines 26:3ac15dfbb66b 35 //
Crazyaboutmachines 26:3ac15dfbb66b 36 //--------------------------------------------------------------------
Crazyaboutmachines 23:1a29761becd2 37
hudakz 0:c5e5d0df6f2a 38
Crazyaboutmachines 29:3af76325f86a 39
Crazyaboutmachines 29:3af76325f86a 40
Crazyaboutmachines 29:3af76325f86a 41 /*************Zivan NG3-G7MICB Charger(Input 230VAC-19A;Output 96 VDC-25A)*****
Crazyaboutmachines 32:977a1b5728e4 42 Processo de carregamento:
Crazyaboutmachines 32:977a1b5728e4 43 (1) Desconectar carregador da rede AC
Crazyaboutmachines 32:977a1b5728e4 44 (2) Conectar carregador as baterias
Crazyaboutmachines 32:977a1b5728e4 45 (3) Conectar carregador da rede AC(talves mais pratico ter botao?)
Crazyaboutmachines 32:977a1b5728e4 46 (4) Carga iniciase automaticamente(?) até uma tensao maxima de 4*27=108V
Crazyaboutmachines 32:977a1b5728e4 47 (5) Para desligar carregador desconectar da rede AC
Crazyaboutmachines 29:3af76325f86a 48
Crazyaboutmachines 29:3af76325f86a 49 Tarefas:
Crazyaboutmachines 32:977a1b5728e4 50 -ver celulas em que o balanceamento nao esta a funcionar
Crazyaboutmachines 32:977a1b5728e4 51 -ver porque as tensões nao se estão a actualizar (por a fazer display da soma das tenções)
Crazyaboutmachines 32:977a1b5728e4 52 -ver porque o charger nao responde as mensagens CAN
Crazyaboutmachines 32:977a1b5728e4 53
Crazyaboutmachines 29:3af76325f86a 54 -acabar de formatar o codigo do BMS encurtando interrupts, programando todas as BMS's e aumentando fiabilidade, etc
Crazyaboutmachines 29:3af76325f86a 55 -ligar carregador e ver que tensoes de CAN e de saida manda cá para fora+ ver que mensagens
Crazyaboutmachines 32:977a1b5728e4 56
Crazyaboutmachines 32:977a1b5728e4 57 Atenção:
Crazyaboutmachines 32:977a1b5728e4 58 -obrigatorio conectar e desconectar as baterias do carregador quando este esta desconectado da rede AC
Crazyaboutmachines 32:977a1b5728e4 59 -em caso de algum problema desligar primeiro ficha da redeAC do carregador e depois desconectar ficha das baterias
Crazyaboutmachines 29:3af76325f86a 60
Crazyaboutmachines 29:3af76325f86a 61 Mensagens:
Crazyaboutmachines 29:3af76325f86a 62 (charger CAN node is 11 by default. So the Id of the message will be 0x60B in
Crazyaboutmachines 29:3af76325f86a 63 hexadecimal)
Crazyaboutmachines 29:3af76325f86a 64
Crazyaboutmachines 29:3af76325f86a 65 Charger->BMS (normally reserved id's)
Crazyaboutmachines 29:3af76325f86a 66 0x380+node_id (period: 1,000S): actual output current, voltage and Ah
Crazyaboutmachines 29:3af76325f86a 67 0x280+node_id (period: 4,000S): alarms flags, hardware start/stop status
Crazyaboutmachines 29:3af76325f86a 68 0x180+node_id (answer for 0x776 message): tambem é uma das respostas durante o precharge
Crazyaboutmachines 29:3af76325f86a 69 0x580+node_id: answer to 0x600 SDO message
Crazyaboutmachines 29:3af76325f86a 70
Crazyaboutmachines 29:3af76325f86a 71 BMS->Charger
Crazyaboutmachines 29:3af76325f86a 72 0x776: (broadcast; from BMS to chargers): current and voltage setpoints, battery detection setpoint
Crazyaboutmachines 29:3af76325f86a 73 0x6C1: (broadcast message; from BMS to charger): only mandatory message BMS need to implement (4s timeout)
Crazyaboutmachines 29:3af76325f86a 74 0x600+node_id: SDO messages
Crazyaboutmachines 29:3af76325f86a 75
Crazyaboutmachines 29:3af76325f86a 76 Reserved id's:
Crazyaboutmachines 29:3af76325f86a 77 0x48A
Crazyaboutmachines 29:3af76325f86a 78 0x68A
Crazyaboutmachines 29:3af76325f86a 79 0x69A
Crazyaboutmachines 29:3af76325f86a 80 0x777
Crazyaboutmachines 29:3af76325f86a 81 0x380+node_id
Crazyaboutmachines 29:3af76325f86a 82 0x180+node_id
Crazyaboutmachines 29:3af76325f86a 83 0x600+node_id
Crazyaboutmachines 29:3af76325f86a 84 0x580+node_id
Crazyaboutmachines 29:3af76325f86a 85 ...remote display default node is 21...
Crazyaboutmachines 29:3af76325f86a 86
Crazyaboutmachines 32:977a1b5728e4 87 Precharge(not used):
Crazyaboutmachines 29:3af76325f86a 88 (ID|Message)
Crazyaboutmachines 29:3af76325f86a 89 To charger:(0x600+node_id | 22-60-60-01-V_HI-V_LO-0-0)
Crazyaboutmachines 29:3af76325f86a 90 From charger:(0x580+node_id | 60-60-60-01-0-0-0-0)
Crazyaboutmachines 29:3af76325f86a 91 From charger:(0x580+node_id | 80-60-60-01-XX-XX-XX-XX)
Crazyaboutmachines 29:3af76325f86a 92 From charger:(0x180+node_id | I_HI-I_LO-V_HI-V_LO-01-'O'-'K'-n)
Crazyaboutmachines 29:3af76325f86a 93 To charger:(0x600+node_id | 22-60-60-02-0-0-0-0)
Crazyaboutmachines 29:3af76325f86a 94 From charger:(0x580+node_id | 60-60-60-02-0-0-0-0)
Crazyaboutmachines 29:3af76325f86a 95 From charger:(0x580+node_id | 80-60-60-02-XX-XX-XX-XX)
Crazyaboutmachines 29:3af76325f86a 96
Crazyaboutmachines 32:977a1b5728e4 97
Crazyaboutmachines 32:977a1b5728e4 98 testar:------------------------------------
Crazyaboutmachines 32:977a1b5728e4 99
Crazyaboutmachines 32:977a1b5728e4 100 -ver se BMS esta realmente a actualizar tensoes comparando tensoes a ser ou nao carregadas
Crazyaboutmachines 32:977a1b5728e4 101
Crazyaboutmachines 32:977a1b5728e4 102 test3:----------------------------
Crazyaboutmachines 32:977a1b5728e4 103 -checkar que o balanceamento de todas as celulas estao a funcionar
Crazyaboutmachines 32:977a1b5728e4 104 -ajustar bms para carga final e amostra da soma total das tensoes
Crazyaboutmachines 32:977a1b5728e4 105
Crazyaboutmachines 32:977a1b5728e4 106 test4:-----------------------------
Crazyaboutmachines 32:977a1b5728e4 107 -carregamento final
Crazyaboutmachines 32:977a1b5728e4 108
Crazyaboutmachines 32:977a1b5728e4 109 test5:-----------------------------
Crazyaboutmachines 32:977a1b5728e4 110 -descarregamento ate metade da tensão p testar aquecimento do balanceamento
Crazyaboutmachines 32:977a1b5728e4 111
Crazyaboutmachines 29:3af76325f86a 112 ******************************************************************************/
Crazyaboutmachines 29:3af76325f86a 113
Crazyaboutmachines 29:3af76325f86a 114
ser1516 21:13ac27349025 115 const unsigned int RX_ID = 0x100;
ser1516 21:13ac27349025 116 const unsigned int TX_ID = 0x101;
hudakz 6:7ff95ce72f6d 117
hudakz 19:872e304d7e17 118 #include "CANnucleo.h"
hudakz 16:a86f339d1c25 119 #include "mbed.h"
hudakz 16:a86f339d1c25 120
ser1516 21:13ac27349025 121 /*
hudakz 17:18d4d0ff26a6 122 * To avaoid name collision with the CAN and CANMessage classes built into the mbed library
hudakz 17:18d4d0ff26a6 123 * the CANnucleo's CAN and CANMessage classes have been moved into the CANnucleo namespace.
hudakz 20:eb1a8042605e 124 * Remember to qualify them with the CANnucleo namespace.
hudakz 17:18d4d0ff26a6 125 */
hudakz 17:18d4d0ff26a6 126 CANnucleo::CAN can(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name
hudakz 17:18d4d0ff26a6 127 CANnucleo::CANMessage rxMsg;
hudakz 17:18d4d0ff26a6 128 CANnucleo::CANMessage txMsg;
ser1516 21:13ac27349025 129 CANnucleo::CANMessage throttle_txMsg;
ser1516 21:13ac27349025 130
ser1516 21:13ac27349025 131
ser1516 21:13ac27349025 132 DigitalOut led(PA_5);
ser1516 21:13ac27349025 133
hudakz 18:22977a898fe9 134 Timer timer;
hudakz 17:18d4d0ff26a6 135 volatile bool msgAvailable = false;
ser1516 21:13ac27349025 136 volatile bool to_send = false;
Crazyaboutmachines 25:76c6f417eb48 137 float cellsv[36];
Crazyaboutmachines 36:00ea3ae2cead 138 int cellst[96];
hudakz 16:a86f339d1c25 139 /**
hudakz 16:a86f339d1c25 140 * @brief 'CAN receive-complete' interrup handler.
hudakz 16:a86f339d1c25 141 * @note Called on arrival of new CAN message.
hudakz 16:a86f339d1c25 142 * Keep it as short as possible.
ser1516 21:13ac27349025 143 * @param
ser1516 21:13ac27349025 144 * @retval
hudakz 16:a86f339d1c25 145 */
ser1516 21:13ac27349025 146 void onMsgReceived()
ser1516 21:13ac27349025 147 {
hudakz 16:a86f339d1c25 148 msgAvailable = true;
hudakz 16:a86f339d1c25 149 }
hudakz 16:a86f339d1c25 150
hudakz 16:a86f339d1c25 151 /**
hudakz 16:a86f339d1c25 152 * @brief Main
hudakz 16:a86f339d1c25 153 * @note
ser1516 21:13ac27349025 154 * @param
hudakz 16:a86f339d1c25 155 * @retval
hudakz 16:a86f339d1c25 156 */
ser1516 21:13ac27349025 157
ser1516 21:13ac27349025 158 bool key_switch = 0;
ser1516 21:13ac27349025 159
Crazyaboutmachines 25:76c6f417eb48 160
Crazyaboutmachines 30:1bc79ae58a42 161 void refresh()
ser1516 21:13ac27349025 162 {
ser1516 21:13ac27349025 163 key_switch = !key_switch;
Crazyaboutmachines 36:00ea3ae2cead 164 led = key_switch;
ser1516 21:13ac27349025 165 to_send=1;
ser1516 21:13ac27349025 166 //printf("controller switch\r\n");
ser1516 21:13ac27349025 167 // to_send = 1;
ser1516 21:13ac27349025 168 }
ser1516 21:13ac27349025 169
Crazyaboutmachines 24:c9c7dcdcbbc5 170 void cvprint(){
Crazyaboutmachines 25:76c6f417eb48 171 int n;
Crazyaboutmachines 32:977a1b5728e4 172 float soma=0;
Crazyaboutmachines 25:76c6f417eb48 173 for(n=35; n>=0; n--){
Crazyaboutmachines 25:76c6f417eb48 174 //printf("cellsv0: %f cvprint\r\n", cellsv[0]);
Crazyaboutmachines 25:76c6f417eb48 175 printf("cell: %d voltage: %f \r\n", n+1,cellsv[n]);
Crazyaboutmachines 36:00ea3ae2cead 176
Crazyaboutmachines 32:977a1b5728e4 177 if(cellsv[n]>=0.1)
Crazyaboutmachines 32:977a1b5728e4 178 {
Crazyaboutmachines 32:977a1b5728e4 179 soma=cellsv[n]+soma;
Crazyaboutmachines 32:977a1b5728e4 180 }
Crazyaboutmachines 32:977a1b5728e4 181 }
Crazyaboutmachines 32:977a1b5728e4 182
Crazyaboutmachines 36:00ea3ae2cead 183 printf("Total battery voltage: %f \r\n", soma);
Crazyaboutmachines 25:76c6f417eb48 184 printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
Crazyaboutmachines 24:c9c7dcdcbbc5 185 }
Crazyaboutmachines 24:c9c7dcdcbbc5 186
Crazyaboutmachines 36:00ea3ae2cead 187 void ctprint(){
Crazyaboutmachines 36:00ea3ae2cead 188 int n;
Crazyaboutmachines 36:00ea3ae2cead 189 for(n=95; n>=0; n--){
Crazyaboutmachines 36:00ea3ae2cead 190 //printf("cellsv0: %f cvprint\r\n", cellsv[0]);
Crazyaboutmachines 36:00ea3ae2cead 191 printf("ntc: %d temperature: %d \r\n", n+1,cellst[n]);
Crazyaboutmachines 36:00ea3ae2cead 192 }
Crazyaboutmachines 36:00ea3ae2cead 193 printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
Crazyaboutmachines 36:00ea3ae2cead 194 }
Crazyaboutmachines 24:c9c7dcdcbbc5 195
Crazyaboutmachines 30:1bc79ae58a42 196 Ticker refresher;
Crazyaboutmachines 25:76c6f417eb48 197 Ticker printer;
Crazyaboutmachines 36:00ea3ae2cead 198 Ticker printer2;
ser1516 21:13ac27349025 199
ser1516 21:13ac27349025 200 typedef union can_union {
ser1516 21:13ac27349025 201 int i[2];
ser1516 21:13ac27349025 202 char bytes[8];
ser1516 21:13ac27349025 203 float f[2];
ser1516 21:13ac27349025 204 } data;
ser1516 21:13ac27349025 205
Crazyaboutmachines 36:00ea3ae2cead 206 typedef union can_union2 {
Crazyaboutmachines 36:00ea3ae2cead 207 int i[2];
Crazyaboutmachines 36:00ea3ae2cead 208 char bytes[8];
Crazyaboutmachines 36:00ea3ae2cead 209 float f[2];
Crazyaboutmachines 36:00ea3ae2cead 210 } data2;
Crazyaboutmachines 36:00ea3ae2cead 211
Crazyaboutmachines 30:1bc79ae58a42 212 //bool to_charge_or_not_to_charge=true; // false = discharge
Crazyaboutmachines 35:a8940aaa101f 213 bool charging = false;
Crazyaboutmachines 30:1bc79ae58a42 214
Crazyaboutmachines 29:3af76325f86a 215 uint8_t motostate=0;
Crazyaboutmachines 27:21239801cfd3 216
Crazyaboutmachines 36:00ea3ae2cead 217 int main(){
hudakz 16:a86f339d1c25 218 can.frequency(1000000); // set bit rate to 1Mbps
hudakz 16:a86f339d1c25 219 can.attach(&onMsgReceived); // attach 'CAN receive-complete' interrupt handler
Crazyaboutmachines 30:1bc79ae58a42 220 refresher.attach(&refresh, 5); // turn on or off
Crazyaboutmachines 25:76c6f417eb48 221
Crazyaboutmachines 25:76c6f417eb48 222 printer.attach(&cvprint, 20); // turn on o
Crazyaboutmachines 36:00ea3ae2cead 223 printer2.attach(&ctprint, 50); // turn on o
Crazyaboutmachines 36:00ea3ae2cead 224
Crazyaboutmachines 36:00ea3ae2cead 225
ser1516 21:13ac27349025 226 led=key_switch;
hudakz 10:66da8731bdb6 227 timer.start(); // start timer
ser1516 21:13ac27349025 228
ser1516 21:13ac27349025 229 printf("started\r\n");
ser1516 21:13ac27349025 230 while(true) {
ser1516 21:13ac27349025 231
ser1516 21:13ac27349025 232 if(msgAvailable) {
ser1516 21:13ac27349025 233 data data;
Crazyaboutmachines 36:00ea3ae2cead 234 data2 data2;
ser1516 21:13ac27349025 235 int len = can.read(rxMsg);
Crazyaboutmachines 36:00ea3ae2cead 236
Crazyaboutmachines 36:00ea3ae2cead 237 if((rxMsg.id==11)||(rxMsg.id==12)||(rxMsg.id==13)){
Crazyaboutmachines 36:00ea3ae2cead 238 data.bytes[0] = rxMsg.data[0];
Crazyaboutmachines 36:00ea3ae2cead 239 data.bytes[1] = rxMsg.data[1];
Crazyaboutmachines 36:00ea3ae2cead 240 data.bytes[2] = rxMsg.data[2];
Crazyaboutmachines 36:00ea3ae2cead 241 data.bytes[3] = rxMsg.data[3];
Crazyaboutmachines 36:00ea3ae2cead 242 msgAvailable = false; // reset flag for next use
Crazyaboutmachines 36:00ea3ae2cead 243 // printf(" Id: %d, data: %f, counter : %d\n", rxMsg.id, data.f[0],rxMsg.data[4]);
Crazyaboutmachines 36:00ea3ae2cead 244 cellsv[(rxMsg.id-11)*12+rxMsg.data[4]-1]=data.f[0];
Crazyaboutmachines 36:00ea3ae2cead 245 //printf("cell: %d\r\n", rxMsg.data[4]);
Crazyaboutmachines 36:00ea3ae2cead 246 /*
Crazyaboutmachines 36:00ea3ae2cead 247 printf("\r\nreceived message ID: \t%d\n\r", rxMsg.id);
Crazyaboutmachines 36:00ea3ae2cead 248 for(int i=0; i<len; i++) {
Crazyaboutmachines 36:00ea3ae2cead 249 printf("\t%x",rxMsg.data[i]);
Crazyaboutmachines 36:00ea3ae2cead 250 }*/
Crazyaboutmachines 36:00ea3ae2cead 251 // printf("\r\n");
Crazyaboutmachines 36:00ea3ae2cead 252 /* if(rxMsg.data[4] == 1) { //counter == 12
Crazyaboutmachines 36:00ea3ae2cead 253
Crazyaboutmachines 36:00ea3ae2cead 254 printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
Crazyaboutmachines 36:00ea3ae2cead 255 }
Crazyaboutmachines 36:00ea3ae2cead 256 */
Crazyaboutmachines 36:00ea3ae2cead 257 // Filtering performed by software:
ser1516 21:13ac27349025 258 }
Crazyaboutmachines 36:00ea3ae2cead 259
Crazyaboutmachines 36:00ea3ae2cead 260
Crazyaboutmachines 36:00ea3ae2cead 261 if((rxMsg.id==21)||(rxMsg.id==22)||(rxMsg.id==23)){
Crazyaboutmachines 36:00ea3ae2cead 262 int len = can.read(rxMsg);
Crazyaboutmachines 36:00ea3ae2cead 263 //printf("olaola\r\n");
Crazyaboutmachines 36:00ea3ae2cead 264 // cellst[(rxMsg.id-21)*32+rxMsg.data[4]-1]=data.f[0];
Crazyaboutmachines 36:00ea3ae2cead 265 data2.bytes[0] = rxMsg.data[0];
Crazyaboutmachines 36:00ea3ae2cead 266 data2.bytes[1] = rxMsg.data[1];
Crazyaboutmachines 36:00ea3ae2cead 267 msgAvailable = false;
Crazyaboutmachines 36:00ea3ae2cead 268 cellst[(rxMsg.id-21)*32+rxMsg.data[2]-1]=data2.i[0];
Crazyaboutmachines 36:00ea3ae2cead 269
Crazyaboutmachines 36:00ea3ae2cead 270 //printf("temp: %d \r\n", rxMsg.data[1]);
Crazyaboutmachines 36:00ea3ae2cead 271 }
Crazyaboutmachines 36:00ea3ae2cead 272
hudakz 0:c5e5d0df6f2a 273 }
ser1516 21:13ac27349025 274 if(to_send) {
ser1516 21:13ac27349025 275 to_send = 0;
Crazyaboutmachines 27:21239801cfd3 276
Crazyaboutmachines 27:21239801cfd3 277
Crazyaboutmachines 27:21239801cfd3 278 //------------------------------------------------
Crazyaboutmachines 27:21239801cfd3 279 //ECU to BMS State
Crazyaboutmachines 26:3ac15dfbb66b 280
Crazyaboutmachines 27:21239801cfd3 281 //motostate: (0|0|0|0|0|0|to_charge_or_not_to_charge|key_switch)
Crazyaboutmachines 27:21239801cfd3 282 txMsg.clear();
Crazyaboutmachines 27:21239801cfd3 283 txMsg.id = 9; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13.
Crazyaboutmachines 27:21239801cfd3 284 txMsg.len = 1;
Crazyaboutmachines 30:1bc79ae58a42 285 motostate = (0b00000001 & key_switch)|((0b00000001 & charging)<<1);
Crazyaboutmachines 29:3af76325f86a 286 txMsg.data[0] = motostate;
Crazyaboutmachines 27:21239801cfd3 287 //------------------------------------------------
Crazyaboutmachines 27:21239801cfd3 288
ser1516 21:13ac27349025 289 if(can.write(txMsg)) {
ser1516 21:13ac27349025 290 printf("sent message\r\n");
ser1516 21:13ac27349025 291 } else {
Crazyaboutmachines 27:21239801cfd3 292 static char count = 0; //desta maneira o count é sempre zero e assim nunca chega a 3??
ser1516 21:13ac27349025 293 count++;
ser1516 21:13ac27349025 294 printf("transmission error\n\r overflow: %x\n\r", count);
ser1516 21:13ac27349025 295 if(count == 3) {
Crazyaboutmachines 23:1a29761becd2 296 count = 0;
Crazyaboutmachines 23:1a29761becd2 297 NVIC_SystemReset(); //faz reset se estiver a falhar o envio de mensagens
ser1516 21:13ac27349025 298 // attach 'CAN receive-complete' interrupt handler
ser1516 21:13ac27349025 299
ser1516 21:13ac27349025 300 }
ser1516 21:13ac27349025 301
hudakz 0:c5e5d0df6f2a 302 }
hudakz 0:c5e5d0df6f2a 303 }
hudakz 0:c5e5d0df6f2a 304 }
hudakz 0:c5e5d0df6f2a 305 }
hudakz 7:2dce8ed51091 306
hudakz 12:e91e44924194 307
hudakz 17:18d4d0ff26a6 308