canbus with intterupt
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:a2f5c6f42674
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 19 15:00:26 2016 +0000 @@ -0,0 +1,53 @@ +#include "mbed.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +Serial pc(USBTX,USBRX); +CAN Canbus(p30,p29); +char counter; +char data[8]; + +//Ticker ticker; + +void send() +{ + if(Canbus.write(CANMessage(20,&data[0],8))); +{ + pc.printf("Message sent!!\n"); + led1= !led1; + counter++; + } +} + +int main() +{ + led1=0; + led2=0; + led3=0; + Canbus.frequency(125000); + + data[0]='0'; + data[1]='1'; + data[2]='2'; + data[3]='3'; + data[4]='4'; + data[5]='5'; + data[6]='6'; + data[7]='7'; + pc.printf("Basliyor!\n"); + //ticker.attach(&send,1); + CANMessage msg; + while(1) { + + if(Canbus.read(msg)); + { + + pc.printf("Message Recieved:%d %d %d %d %d %d %d %d\n",msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); + led2=!led2; + }///if + wait(0.5); + led3=!led3; + wait(0.5); + }///While +}////Main///////