example showing how to use the mbed CAN API

Dependencies:   mbed CANMsg

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Fri Feb 08 13:16:55 2019 +0000
Parent:
8:c65afde7f7f5
Commit message:
Updated.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c65afde7f7f5 -r 3211e88e30a5 main.cpp
--- a/main.cpp	Tue Feb 05 19:03:26 2019 +0000
+++ b/main.cpp	Fri Feb 08 13:16:55 2019 +0000
@@ -22,8 +22,6 @@
 
 #if defined(TARGET_STM32F103C8T6)
     #define LED_PIN     PC_13
-    #define USBTX       PA_2
-    #define USBRX       PA_3
     const int           OFF = 1;
     const int           ON = 0;
 #else
@@ -45,6 +43,7 @@
 
 Serial              pc(USBTX, USBRX);
 CAN                 can(PB_8, PB_9);  // CAN Rx pin name, CAN Tx pin name
+//CAN                 can(p30, p29);  // CAN Rx pin name, CAN Tx pin name
 CANMsg              rxMsg;
 CANMsg              txMsg;
 DigitalOut          led(LED_PIN);
@@ -80,6 +79,8 @@
 void onCanReceived(void)
 {
     can.read(rxMsg);
+    pc.printf("-------------------------------------\r\n");
+    pc.printf("CAN message received\r\n");
     printMsg(rxMsg);
 
     if (rxMsg.id == RX_ID) {
@@ -116,7 +117,7 @@
     pc.printf("CAN_Hello board #2\r\n");
 #endif
     while(1) {
-        if(timer.read_ms() >= 1000) {    // check for timeout
+        if(timer.read_ms() >= 2000) {    // check for timeout
             timer.stop();                // stop timer
             timer.reset();               // reset timer
             counter++;                   // increment counter
@@ -130,6 +131,7 @@
             if(can.write(txMsg)) {       // transmit message
                 led = OFF;               // turn the LED off
                 pc.printf("-------------------------------------\r\n");
+                pc.printf("-------------------------------------\r\n");
                 pc.printf("CAN message sent\r\n");
                 printMsg(txMsg);
                 pc.printf("  counter = %d\r\n", counter);