7 years, 7 months ago.

CAN on LPCXpresso1549

Hi, Is CAN implemented yet on this board? I try to run some simple CAN code on this device, but nothing seems to happen. I put some LEDs in my CAN tx and CAN rx functions, but with no activity. Allso the led in the main function is not blinking.

Here is the code:

#include "mbed.h"

DigitalOut r1(LED1);
DigitalOut g1(LED2);
DigitalOut b1(LED3);

CAN can(P0_11, P0_31);

Ticker tick;
Serial pc(USBTX,USBRX);
CANMessage msg;
char data[8];



void __can_rx ()
{
    b1=!b1;
    pc.printf("CAN PACKET RECIEVED...\r\n");
    pc.printf("======================\r\n");
    for(int i= 0; i< 8; i++) {
        pc.printf("DATA [%i] = %#04X \r\n",i,msg.data[i]);
    }

    pc.printf("\033[3A"); 
}

void __can_tx()
{
            g1 = !g1;
            data[0] = (char)(0x01); //EC1 status req
            data[1] = (char)(0x02);
            data[2] = (char)(0x03);
            data[3] = (char)(0x04);
            data[4] = (char)(0x05);
            data[5] = (char)(0x06);
            data[6] = (char)(0x07);
            data[7] = (char)(rand()%255);
            if(can.write(CANMessage(0x55,data,8))) {}
}

int main()
{
    can.frequency(500000); //CAN at 500k
    can.attach(&__can_rx); //ISR for can
    tick.attach(&__can_tx, 1.0);
    pc.baud(921600);
    pc.printf("HELLO, THIS IS A SIMPLE CAN BUTTSNIFFER! \r\n");

    while(1) {
        
        r1 = !r1;
        wait(0.5);

    }
}

So, any help would be appreciated.

Question relating to:

Nevermind...it works now. I have commented all regarding CAN, then recompiled the project. Then I uncommented step by step CAN features, and at the end everything worked fine...go figure. RGDS

posted by Gorazd Rosbach 12 May 2017
Be the first to answer this question.