Canbus with interrupt

Dependencies:   mbed

main.cpp

Committer:
cagriakalin
Date:
2016-01-19
Revision:
0:8cad60da149a

File content as of revision 0:8cad60da149a:

#include "mbed.h"

CAN canObject(p30,p29);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Serial pc(USBTX, USBRX);

void test(void) {
    led1= !led1;
    return;
}

bool speed() {
    char can_msg[3];
    can_msg[0] = 0x3D;
    can_msg[1] = 0x30;
    can_msg[2] = 0x00;

    bool success = canObject.write(CANMessage(0x211, can_msg, 3));
    led2 = !led2;
    return success;
}

int main()
{
    pc.baud(115200);
    wait(0.2);
    canObject.frequency(250000);
    wait(0.2);

    canObject.attach(&test, CAN::RxIrq);

    wait(1);
    if(speed());
    wait(1);
    if(speed());

    while(1) {

    }
}