Simple test CAN bus

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Mamamamax
Date:
Wed May 15 16:15:52 2019 +0000
Commit message:
Test can bus

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 15 16:15:52 2019 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut led(LED1);
+DigitalOut CanEnable(PB_12);
+
+CAN CanBus(PA_11, PA_12, 1000000);
+
+Ticker ticker;
+char counter = 0;
+
+void send() {
+    pc.printf("send()\n");
+    if(CanBus.write(CANMessage(1337, &counter, 1))) {
+        pc.printf("wloop()\n");
+        counter++;
+        pc.printf("Message sent: %d\n", counter);
+    } 
+    led = !led;
+}
+
+
+int main()
+{
+    pc.baud(115200);
+    pc.printf("Hello World !\n");
+    CanEnable = 1;
+    wait(0.2);
+    CanEnable = 0;
+
+    ticker.attach(&send, 1);
+    CANMessage msg;
+    while(1) {
+        pc.printf("loop()\n");
+        if(CanBus.read(msg)) {
+            pc.printf("Message received: %d\n", msg.data[0]);
+            led = !led;
+        } 
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 15 16:15:52 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file