Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 2 months ago.
CAN based communication ??
A code for CAN based communication
1 Answer
11 years, 1 month ago.
Did you try the code from the mbed library. It has not worked for us but perhaps you can get it to work.
no it dint work. The code is
1. sending code:
- include "mbed.h"
- include "CAN.h" DigitalOut led1(LED1); CAN can1(p30, p29); Serial pc(USBTX, USBRX); char counter=0; int main() { pc.baud(9600); can1.frequency(125000); while(1) { if(can1.write(CANMessage(0x42, &counter, 1))) { led1=1; counter++; pc.printf("Message sent: %d\n", counter); } wait(3.0); led1=0; wait(3.0); } }
2. Receiving code:
- include "mbed.h"
- include "CAN.h" DigitalOut led1(LED1); Serial pc(USBTX,USBRX); CAN can2(p30, p29); int main() { CANMessage msg; pc.baud(9600); can2.frequency(125000); while(1) { if(can2.read(msg)) { led1=0; pc.printf("Message received:%d\n", msg.data[0]);
} wait(3.0); led1=1; wait(3.0); } }
posted by 10 Nov 2013