pub
Dependencies: CANnucleo mbed-dev
Fork of CANnucleo_Hello by
Diff: main.cpp
- Revision:
- 28:50dcf8aea3ee
- Parent:
- 27:f71400b1fa56
- Child:
- 29:dde6c4aef759
diff -r f71400b1fa56 -r 50dcf8aea3ee main.cpp --- a/main.cpp Wed Mar 08 19:26:27 2017 +0000 +++ b/main.cpp Wed Mar 08 19:42:46 2017 +0000 @@ -117,12 +117,12 @@ timer.stop(); // stop timer timer.reset(); // reset timer counter++; // increment counter + voltage = (analogIn * 3.3f)/4096.0f;// read small floating voltage at analog input txMsg.clear(); // clear Tx message storage txMsg.id = TX_ID; // set ID - voltage = (analogIn * 3.3f)/4096.0f;// small floating voltage at analog input txMsg << counter << voltage; // append data (total data length must be <= 8 bytes!) - led = OFF; // turn LED off if(can->write(txMsg)) { // transmit message + led = OFF; // turn LED off pc->printf("-----------------------------------\r\n"); pc->printf("CAN message sent\r\n"); printMsg(txMsg); @@ -135,14 +135,14 @@ if(msgAvailable) { msgAvailable = false; // reset flag for next use can->read(rxMsg); // read message into Rx message storage + led = ON; // turn LED on pc->printf("CAN message received\r\n"); printMsg(rxMsg); // Filtering performed by software: - if(rxMsg.id == RX_ID) { // About filtering performed by hardware see comments in CANnucleo.cpp - rxMsg >> counter >> voltage; // extract data + if(rxMsg.id == RX_ID) { // about filtering performed by hardware see comments in CANnucleo.cpp + rxMsg >> counter >> voltage; // extract data from the received CAN message pc->printf(" counter = %d\r\n", counter); pc->printf(" voltage = %e V\r\n", voltage); - led = ON; // turn LED on timer.start(); // transmission lag } }