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.
Dependencies: SoftPWM MotorSMLAP
Fork of CANnucleo_Hello by
Diff: main.cpp
- Revision:
- 27:50dcf8aea3ee
- Parent:
- 26:f71400b1fa56
- Child:
- 28:dde6c4aef759
--- 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
}
}
