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 Stephen Dickey

main.cpp

Committer:
dixter1
Date:
2013-12-14
Revision:
2:c4ad86683060
Parent:
1:15b5edb4a91f
Child:
3:048ec5c2dc14

File content as of revision 2:c4ad86683060:

#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;

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;
    
    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();
    }
}