Canbus with interrupt

Dependencies:   mbed

Revision:
0:8cad60da149a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jan 19 15:02:11 2016 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+CAN canObject(p30,p29);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+Serial pc(USBTX, USBRX);
+
+void test(void) {
+    led1= !led1;
+    return;
+}
+
+bool speed() {
+    char can_msg[3];
+    can_msg[0] = 0x3D;
+    can_msg[1] = 0x30;
+    can_msg[2] = 0x00;
+
+    bool success = canObject.write(CANMessage(0x211, can_msg, 3));
+    led2 = !led2;
+    return success;
+}
+
+int main()
+{
+    pc.baud(115200);
+    wait(0.2);
+    canObject.frequency(250000);
+    wait(0.2);
+
+    canObject.attach(&test, CAN::RxIrq);
+
+    wait(1);
+    if(speed());
+    wait(1);
+    if(speed());
+
+    while(1) {
+
+    }
+}