2

I want to receive an extended CAN-Message. I send a extended CAN-Message, but nothing happens. Maybe somebody have an idea what the problem is..

It works with a standard CAN-Message.

Thanks in advance.

// demo: CAN-BUS Shield, send data
// loovee@seeed.cc

#include <mcp_can.h>
#include <SPI.h>

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

void setup()
{
    Serial.begin(115200);

    while (CAN_OK != CAN.begin(CAN_250KBPS))              // init can bus : baudrate = 250k
    {

        CAN.init_Mask(0,1,0);
        CAN.init_Filt(0,1,0);

        Serial.println("CAN BUS Shield init fail");
        Serial.println(" Init CAN BUS Shield again");
        delay(100);
    }
    Serial.println("CAN BUS Shield init ok!");
}

unsigned char len = 0;
unsigned char buf[30];

void loop()
{    
    CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
    unsigned long canId = CAN.getCanId();
    Serial.println("-----------------------------");
    Serial.print("Get Data from ID: 0x");
    Serial.println(canId, HEX);
    Serial.println("Data content:");
    for(int i = 0; i<len; i++) // print the data
    {
        Serial.print(buf[i]);
        Serial.print("\t");
    }
    Serial.println("-----------------------------");
}

0 Answers0