Canbus with interrupt

Dependencies:   mbed

Committer:
cagriakalin
Date:
Tue Jan 19 15:02:11 2016 +0000
Revision:
0:8cad60da149a
Canbus with interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cagriakalin 0:8cad60da149a 1 #include "mbed.h"
cagriakalin 0:8cad60da149a 2
cagriakalin 0:8cad60da149a 3 CAN canObject(p30,p29);
cagriakalin 0:8cad60da149a 4 DigitalOut led1(LED1);
cagriakalin 0:8cad60da149a 5 DigitalOut led2(LED2);
cagriakalin 0:8cad60da149a 6 Serial pc(USBTX, USBRX);
cagriakalin 0:8cad60da149a 7
cagriakalin 0:8cad60da149a 8 void test(void) {
cagriakalin 0:8cad60da149a 9 led1= !led1;
cagriakalin 0:8cad60da149a 10 return;
cagriakalin 0:8cad60da149a 11 }
cagriakalin 0:8cad60da149a 12
cagriakalin 0:8cad60da149a 13 bool speed() {
cagriakalin 0:8cad60da149a 14 char can_msg[3];
cagriakalin 0:8cad60da149a 15 can_msg[0] = 0x3D;
cagriakalin 0:8cad60da149a 16 can_msg[1] = 0x30;
cagriakalin 0:8cad60da149a 17 can_msg[2] = 0x00;
cagriakalin 0:8cad60da149a 18
cagriakalin 0:8cad60da149a 19 bool success = canObject.write(CANMessage(0x211, can_msg, 3));
cagriakalin 0:8cad60da149a 20 led2 = !led2;
cagriakalin 0:8cad60da149a 21 return success;
cagriakalin 0:8cad60da149a 22 }
cagriakalin 0:8cad60da149a 23
cagriakalin 0:8cad60da149a 24 int main()
cagriakalin 0:8cad60da149a 25 {
cagriakalin 0:8cad60da149a 26 pc.baud(115200);
cagriakalin 0:8cad60da149a 27 wait(0.2);
cagriakalin 0:8cad60da149a 28 canObject.frequency(250000);
cagriakalin 0:8cad60da149a 29 wait(0.2);
cagriakalin 0:8cad60da149a 30
cagriakalin 0:8cad60da149a 31 canObject.attach(&test, CAN::RxIrq);
cagriakalin 0:8cad60da149a 32
cagriakalin 0:8cad60da149a 33 wait(1);
cagriakalin 0:8cad60da149a 34 if(speed());
cagriakalin 0:8cad60da149a 35 wait(1);
cagriakalin 0:8cad60da149a 36 if(speed());
cagriakalin 0:8cad60da149a 37
cagriakalin 0:8cad60da149a 38 while(1) {
cagriakalin 0:8cad60da149a 39
cagriakalin 0:8cad60da149a 40 }
cagriakalin 0:8cad60da149a 41 }