Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Can_sniffer_BMS4 by
main.cpp@34:8e99b3f3114c, 2016-10-28 (annotated)
- Committer:
- Crazyaboutmachines
- Date:
- Fri Oct 28 15:47:49 2016 +0000
- Revision:
- 34:8e99b3f3114c
- Parent:
- 33:74db6193bc6b
- Child:
- 35:a8940aaa101f
reading cells during discharge
Who changed what in which revision?
User | Revision | Line number | New 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]; |
hudakz | 16:a86f339d1c25 | 138 | /** |
hudakz | 16:a86f339d1c25 | 139 | * @brief 'CAN receive-complete' interrup handler. |
hudakz | 16:a86f339d1c25 | 140 | * @note Called on arrival of new CAN message. |
hudakz | 16:a86f339d1c25 | 141 | * Keep it as short as possible. |
ser1516 | 21:13ac27349025 | 142 | * @param |
ser1516 | 21:13ac27349025 | 143 | * @retval |
hudakz | 16:a86f339d1c25 | 144 | */ |
ser1516 | 21:13ac27349025 | 145 | void onMsgReceived() |
ser1516 | 21:13ac27349025 | 146 | { |
hudakz | 16:a86f339d1c25 | 147 | msgAvailable = true; |
hudakz | 16:a86f339d1c25 | 148 | } |
hudakz | 16:a86f339d1c25 | 149 | |
hudakz | 16:a86f339d1c25 | 150 | /** |
hudakz | 16:a86f339d1c25 | 151 | * @brief Main |
hudakz | 16:a86f339d1c25 | 152 | * @note |
ser1516 | 21:13ac27349025 | 153 | * @param |
hudakz | 16:a86f339d1c25 | 154 | * @retval |
hudakz | 16:a86f339d1c25 | 155 | */ |
ser1516 | 21:13ac27349025 | 156 | |
ser1516 | 21:13ac27349025 | 157 | bool key_switch = 0; |
ser1516 | 21:13ac27349025 | 158 | |
Crazyaboutmachines | 25:76c6f417eb48 | 159 | |
Crazyaboutmachines | 30:1bc79ae58a42 | 160 | void refresh() |
ser1516 | 21:13ac27349025 | 161 | { |
ser1516 | 21:13ac27349025 | 162 | key_switch = !key_switch; |
Crazyaboutmachines | 30:1bc79ae58a42 | 163 | // led = key_switch; |
ser1516 | 21:13ac27349025 | 164 | to_send=1; |
ser1516 | 21:13ac27349025 | 165 | //printf("controller switch\r\n"); |
ser1516 | 21:13ac27349025 | 166 | // to_send = 1; |
ser1516 | 21:13ac27349025 | 167 | } |
ser1516 | 21:13ac27349025 | 168 | |
Crazyaboutmachines | 24:c9c7dcdcbbc5 | 169 | void cvprint(){ |
Crazyaboutmachines | 25:76c6f417eb48 | 170 | int n; |
Crazyaboutmachines | 32:977a1b5728e4 | 171 | float soma=0; |
Crazyaboutmachines | 25:76c6f417eb48 | 172 | for(n=35; n>=0; n--){ |
Crazyaboutmachines | 25:76c6f417eb48 | 173 | //printf("cellsv0: %f cvprint\r\n", cellsv[0]); |
Crazyaboutmachines | 25:76c6f417eb48 | 174 | printf("cell: %d voltage: %f \r\n", n+1,cellsv[n]); |
Crazyaboutmachines | 32:977a1b5728e4 | 175 | |
Crazyaboutmachines | 32:977a1b5728e4 | 176 | if(cellsv[n]>=0.1) |
Crazyaboutmachines | 32:977a1b5728e4 | 177 | { |
Crazyaboutmachines | 32:977a1b5728e4 | 178 | soma=cellsv[n]+soma; |
Crazyaboutmachines | 32:977a1b5728e4 | 179 | } |
Crazyaboutmachines | 32:977a1b5728e4 | 180 | } |
Crazyaboutmachines | 32:977a1b5728e4 | 181 | |
Crazyaboutmachines | 32:977a1b5728e4 | 182 | printf("Total battery voltage: %f \r\n", soma); |
Crazyaboutmachines | 25:76c6f417eb48 | 183 | printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n"); |
Crazyaboutmachines | 24:c9c7dcdcbbc5 | 184 | } |
Crazyaboutmachines | 24:c9c7dcdcbbc5 | 185 | |
Crazyaboutmachines | 24:c9c7dcdcbbc5 | 186 | |
Crazyaboutmachines | 30:1bc79ae58a42 | 187 | Ticker refresher; |
Crazyaboutmachines | 25:76c6f417eb48 | 188 | Ticker printer; |
ser1516 | 21:13ac27349025 | 189 | |
ser1516 | 21:13ac27349025 | 190 | typedef union can_union { |
ser1516 | 21:13ac27349025 | 191 | int i[2]; |
ser1516 | 21:13ac27349025 | 192 | char bytes[8]; |
ser1516 | 21:13ac27349025 | 193 | float f[2]; |
ser1516 | 21:13ac27349025 | 194 | } data; |
ser1516 | 21:13ac27349025 | 195 | |
Crazyaboutmachines | 30:1bc79ae58a42 | 196 | //bool to_charge_or_not_to_charge=true; // false = discharge |
Crazyaboutmachines | 34:8e99b3f3114c | 197 | bool charging = true; |
Crazyaboutmachines | 30:1bc79ae58a42 | 198 | |
Crazyaboutmachines | 29:3af76325f86a | 199 | uint8_t motostate=0; |
Crazyaboutmachines | 27:21239801cfd3 | 200 | |
ser1516 | 21:13ac27349025 | 201 | int main() |
ser1516 | 21:13ac27349025 | 202 | |
ser1516 | 21:13ac27349025 | 203 | { |
hudakz | 16:a86f339d1c25 | 204 | can.frequency(1000000); // set bit rate to 1Mbps |
hudakz | 16:a86f339d1c25 | 205 | can.attach(&onMsgReceived); // attach 'CAN receive-complete' interrupt handler |
Crazyaboutmachines | 30:1bc79ae58a42 | 206 | refresher.attach(&refresh, 5); // turn on or off |
Crazyaboutmachines | 25:76c6f417eb48 | 207 | |
Crazyaboutmachines | 25:76c6f417eb48 | 208 | printer.attach(&cvprint, 20); // turn on o |
ser1516 | 21:13ac27349025 | 209 | led=key_switch; |
hudakz | 10:66da8731bdb6 | 210 | timer.start(); // start timer |
ser1516 | 21:13ac27349025 | 211 | |
ser1516 | 21:13ac27349025 | 212 | printf("started\r\n"); |
ser1516 | 21:13ac27349025 | 213 | while(true) { |
ser1516 | 21:13ac27349025 | 214 | |
ser1516 | 21:13ac27349025 | 215 | if(msgAvailable) { |
ser1516 | 21:13ac27349025 | 216 | data data; |
ser1516 | 21:13ac27349025 | 217 | int len = can.read(rxMsg); |
ser1516 | 21:13ac27349025 | 218 | data.bytes[0] = rxMsg.data[0]; |
ser1516 | 21:13ac27349025 | 219 | data.bytes[1] = rxMsg.data[1]; |
ser1516 | 21:13ac27349025 | 220 | data.bytes[2] = rxMsg.data[2]; |
ser1516 | 21:13ac27349025 | 221 | data.bytes[3] = rxMsg.data[3]; |
ser1516 | 21:13ac27349025 | 222 | msgAvailable = false; // reset flag for next use |
Crazyaboutmachines | 25:76c6f417eb48 | 223 | // printf(" Id: %d, data: %f, counter : %d\n", rxMsg.id, data.f[0],rxMsg.data[4]); |
Crazyaboutmachines | 25:76c6f417eb48 | 224 | cellsv[(rxMsg.id-11)*12+rxMsg.data[4]-1]=data.f[0]; |
Crazyaboutmachines | 25:76c6f417eb48 | 225 | //printf("cell: %d\r\n", rxMsg.data[4]); |
ser1516 | 21:13ac27349025 | 226 | /* |
ser1516 | 21:13ac27349025 | 227 | printf("\r\nreceived message ID: \t%d\n\r", rxMsg.id); |
ser1516 | 21:13ac27349025 | 228 | for(int i=0; i<len; i++) { |
ser1516 | 21:13ac27349025 | 229 | printf("\t%x",rxMsg.data[i]); |
ser1516 | 21:13ac27349025 | 230 | }*/ |
Crazyaboutmachines | 25:76c6f417eb48 | 231 | // printf("\r\n"); |
Crazyaboutmachines | 25:76c6f417eb48 | 232 | /* if(rxMsg.data[4] == 1) { //counter == 12 |
ser1516 | 21:13ac27349025 | 233 | |
ser1516 | 21:13ac27349025 | 234 | printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n"); |
ser1516 | 21:13ac27349025 | 235 | } |
Crazyaboutmachines | 24:c9c7dcdcbbc5 | 236 | */ |
ser1516 | 21:13ac27349025 | 237 | // Filtering performed by software: |
hudakz | 0:c5e5d0df6f2a | 238 | } |
ser1516 | 21:13ac27349025 | 239 | if(to_send) { |
ser1516 | 21:13ac27349025 | 240 | to_send = 0; |
Crazyaboutmachines | 27:21239801cfd3 | 241 | |
Crazyaboutmachines | 27:21239801cfd3 | 242 | |
Crazyaboutmachines | 27:21239801cfd3 | 243 | //------------------------------------------------ |
Crazyaboutmachines | 27:21239801cfd3 | 244 | //ECU to BMS State |
Crazyaboutmachines | 26:3ac15dfbb66b | 245 | |
Crazyaboutmachines | 27:21239801cfd3 | 246 | //motostate: (0|0|0|0|0|0|to_charge_or_not_to_charge|key_switch) |
Crazyaboutmachines | 27:21239801cfd3 | 247 | txMsg.clear(); |
Crazyaboutmachines | 27:21239801cfd3 | 248 | txMsg.id = 9; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. |
Crazyaboutmachines | 27:21239801cfd3 | 249 | txMsg.len = 1; |
Crazyaboutmachines | 30:1bc79ae58a42 | 250 | motostate = (0b00000001 & key_switch)|((0b00000001 & charging)<<1); |
Crazyaboutmachines | 29:3af76325f86a | 251 | txMsg.data[0] = motostate; |
Crazyaboutmachines | 27:21239801cfd3 | 252 | //------------------------------------------------ |
Crazyaboutmachines | 27:21239801cfd3 | 253 | |
ser1516 | 21:13ac27349025 | 254 | if(can.write(txMsg)) { |
ser1516 | 21:13ac27349025 | 255 | printf("sent message\r\n"); |
ser1516 | 21:13ac27349025 | 256 | } else { |
Crazyaboutmachines | 27:21239801cfd3 | 257 | static char count = 0; //desta maneira o count é sempre zero e assim nunca chega a 3?? |
ser1516 | 21:13ac27349025 | 258 | count++; |
ser1516 | 21:13ac27349025 | 259 | printf("transmission error\n\r overflow: %x\n\r", count); |
ser1516 | 21:13ac27349025 | 260 | if(count == 3) { |
Crazyaboutmachines | 23:1a29761becd2 | 261 | count = 0; |
Crazyaboutmachines | 23:1a29761becd2 | 262 | NVIC_SystemReset(); //faz reset se estiver a falhar o envio de mensagens |
ser1516 | 21:13ac27349025 | 263 | // attach 'CAN receive-complete' interrupt handler |
ser1516 | 21:13ac27349025 | 264 | |
ser1516 | 21:13ac27349025 | 265 | } |
ser1516 | 21:13ac27349025 | 266 | |
hudakz | 0:c5e5d0df6f2a | 267 | } |
hudakz | 0:c5e5d0df6f2a | 268 | } |
hudakz | 0:c5e5d0df6f2a | 269 | } |
hudakz | 0:c5e5d0df6f2a | 270 | } |
hudakz | 7:2dce8ed51091 | 271 | |
hudakz | 12:e91e44924194 | 272 | |
hudakz | 17:18d4d0ff26a6 | 273 |