![](/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:
- 14:e12ebd1260b1
- Parent:
- 13:e741def3e4ff
- Child:
- 15:6449443e2207
diff -r e741def3e4ff -r e12ebd1260b1 main.cpp --- a/main.cpp Wed Jul 27 09:16:40 2016 +0000 +++ b/main.cpp Wed Jul 27 10:25:42 2016 +0000 @@ -21,7 +21,7 @@ #include "mbed.h" -#define TARGET_STM32F103C8T6 1 // comment out this line when using official NUCLEO boards! +//#define TARGET_STM32F103C8T6 1 // comment out this line when using official NUCLEO boards! #define BOARD1 1 // comment out this line when compiling for board #2 #if defined(TARGET_STM32F103C8T6) @@ -46,17 +46,9 @@ Timer timer; CAN can(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name CANMessage rxMsg; -CANMessage txMsg; char counter = 0; -/** - * @brief Main - * @note - * @param - * @retval - */ -int main() { - +int main() { #if defined(BOARD1) led = ON; // turn LED on timer.start(); // start timer @@ -65,14 +57,12 @@ #endif while(1) { - if(timer.read_ms() >= 200) { // check for timeout - timer.stop(); // stop timer - timer.reset(); // reset timer - counter++; // increment counter - txMsg.id = TX_ID; // set ID - txMsg.data[0] = counter; // set data - led = OFF; // turn LED off - if(can.write(txMsg)) // transmit message + if(timer.read_ms() >= 200) { // check for timeout + timer.stop(); // stop timer + timer.reset(); // reset timer + counter++; // increment counter + led = OFF; // turn LED off + if(can.write(CANMessage(TX_ID, &counter, 1))) // transmit message printf("CAN message sent\r\n"); else printf("Transmission error\r\n"); @@ -85,14 +75,14 @@ printf(" Length = %d\r\n", rxMsg.len); printf(" Data ="); for(int i = 0; i < rxMsg.len; i++) - printf(" %x", rxMsg.data[i]); + printf(" 0x%.2x", rxMsg.data[i]); printf("\r\n"); if(rxMsg.id == RX_ID) { - counter = rxMsg.data[0]; // set counter - printf("counter = %d\r\n", counter); - led = !led; // set LED - timer.start(); // transmission lag + counter = rxMsg.data[0]; // set counter + printf("counter = %d\r\n", counter); // print counter + led = ON; // set LED + timer.start(); // transmission lag } } }