Testing program for Interrupts

Dependencies:   mbed

Committer:
alexliao1995
Date:
Wed Mar 19 20:38:33 2014 +0000
Revision:
0:0a01a8b970fc
Test for CAN Interrupt;

Who changed what in which revision?

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