This tests the CAN interface between two LISA C027 MBED Boards. By connecting the two boards, pins 1,2,3 respectively on the CAN interface, and loading and executing this code on BOTH boards, CAN messages will be received, and printed, on the PC-USB console interface of both devices.
Dependencies: C027-REVB UbloxUSBModem mbed
Fork of C027_ModemTransparentUSBCDC_revb by
main.cpp
- Committer:
- dixter1
- Date:
- 2013-12-15
- Revision:
- 3:048ec5c2dc14
- Parent:
- 2:c4ad86683060
File content as of revision 3:048ec5c2dc14:
#include "mbed.h" #include "C027.h" Ticker ticker; DigitalOut led1(LED); DigitalOut led2(LED1); CAN can1(CANRD, CANTD); Serial pc(USBTX, USBRX); char counter = 0; // this function creates a CAN message with a counter in it // and sends it on the CAN interface void send() { if(can1.write(CANMessage(1337, &counter, 1))) { pc.printf("Message sent: %d\r\n", counter); counter++; } led1 = !led1; } int main() { DigitalOut can_standby(CANS); // enable the CAN interface // take it out of standby can_standby = 0; // specify the baud rate for communications // with the serial console to the PC host. pc.baud(MDMBAUD); pc.printf( "Starting CAN Testing\r\n"); CANMessage msg; while(1) { if(can1.read(msg)) { pc.printf("Message received: %d\r\n", msg.data[0]); led2 = !led2; } wait(0.2); // send a new message. send(); } }