Nucleo by Cach

Dependencies:   C12832 CANnucleo LM75B mbed

Fork of CANnucleo_Hello by Zoltan Hudak

Revision:
5:c6503b7ae971
Parent:
4:ccf4ac2deac8
Child:
6:7ff95ce72f6d
diff -r ccf4ac2deac8 -r c6503b7ae971 main.cpp
--- a/main.cpp	Sat Jul 25 19:43:00 2015 +0000
+++ b/main.cpp	Fri Oct 23 19:54:49 2015 +0000
@@ -35,12 +35,12 @@
 #endif
 
 DigitalOut      led(LED1);
-int             ledTarget;
+int             ledReceived;
 Timer           timer;
-CAN             can(PA_11, PA_12);  // rx, tx
+CAN             can(PA_11, PA_12);  // CAN Rx pin name, CAN Tx pin name, Automatic recovery from bus-off state enabled by default
 CANMessage      rxMsg;
 CANMessage      txMsg;
-long int        counter = 0;
+int             counter = 0;
 volatile bool   msgAvailable = false;
 
 /**
@@ -61,8 +61,8 @@
  * @retval
  */
 int main() {
-    can.frequency(1000000);                     // Initialize CAN and set bit rate to 1Mbps
-    can.attach(&onMsgReceived, CAN::RxIrq);     // attach 'CAN receive complete' interrupt handler
+    can.frequency(1000000);                     // set bit rate to 1Mbps
+    can.attach(&onMsgReceived, CAN::RxIrq);     // attach 'CAN receive-complete' interrupt handler
     timer.reset();
 #if defined(BOARD1)
     led = 1;
@@ -78,8 +78,8 @@
             counter++;                          // increment counter
             txMsg.clear();                      // clear Tx message storage
             txMsg.id = TX_ID;                   // set ID
-            txMsg << counter;                   // append first data item (always make sure that CAN message total data lenght <= 8 bytes!)
-            txMsg << led.read();                // append second data item (always make sure that CAN message total data lenght <= 8 bytes!)
+            txMsg << counter;                   // append first data item (make sure that CAN message total data lenght <= 8 bytes!)
+            txMsg << led.read();                // append second data item (make sure that CAN message total data lenght <= 8 bytes!)
             can.write(txMsg);                   // transmit message
             printf("CAN message sent\r\n");
             led = 0;                            // turn off LED
@@ -98,8 +98,8 @@
             printf("\r\n");            
             if(rxMsg.id == RX_ID) {             // if ID matches
                 rxMsg >> counter;               // extract first data item
-                rxMsg >> ledTarget;             // extract second data item
-                led = ledTarget;                // set LED
+                rxMsg >> ledReceived;           // extract second data item
+                led = ledReceived;              // set LED
                 printf("counter = %d\r\n", counter);
                 timer.start();
             }