Longan-Labs / Arduino_CAN_BUS_MCP2515

Arduino CAN Bus library, MCP2515/MCP2551
https://www.longan-labs.cc/
MIT License
118 stars 371 forks source link

Extended ID issue #17

Closed Toootless closed 6 years ago

Toootless commented 6 years ago

I am trying to send information to extended address for GM SW can. If I add the address to the line: byte sndStat4 = CAN0.sendMsgBuf(0x810EC4040, 8, data4); byte sndStat5 = CAN0.sendMsgBuf(0x810EC8040, 8, data5); I get Standard ID: 0x040 DLC: 8 Data: 0x47 0x36 0x52 0x53 0x31 0x45 0x34 0x33 Standard ID: 0x040 DLC: 8 Data: 0x45 0x55 0x36 0x30 0x30 0x32 0x36 0x30 This is the data I sent but the wrong ID.

If I send byte sndStat6 = CAN0.sendMsgBuf(0x812CA040, 8, data6); // Engine_Information_1_LS I get Extended ID: 0x012CC040 DLC: 8 Data: 0x01 0x01 0xCF 0x8D 0x00 0x55 0x06 0x6D

also, I am trying to send around 12 different can signals but only see maybe 4 sent back. /* CAN Loopback Example

include

include

// CAN TX Variables unsigned long prevTX = 0; // Variable to store last execution time unsigned long prevTX1 = 0; // Variable to store last execution time const unsigned int invlTX = 1000; // One second interval constant const unsigned int invlTX1 = 1000; // One second interval constant unsigned long prevTX2 = 0; // Variable to store last execution time unsigned long prevTX3 = 0; // Variable to store last execution time const unsigned int invlTX2 = 1000; // One second interval constant const unsigned int invlTX3 = 1000; // One second interval constant unsigned long prevTX4 = 0; // Variable to store last execution time unsigned long prevTX5 = 0; // Variable to store last execution time const unsigned int invlTX4 = 1000; // One second interval constant const unsigned int invlTX5 = 1000; // One second interval constant

byte data0[] = {0xFE, 0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00}; // 101 command byte data1[] = {0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // VNMF_LS_621_BCM byte data2[] = {0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // SW CAN $624 byte data3[] = {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // VNMF_LS_62C_IPC CGM_LS IPC_LS byte data4[] = {0x47, 0x36, 0x52, 0x53, 0x31, 0x45, 0x34, 0x33}; // vin 2 0to 9 hex to accii G6RS1E43 byte data5[] = {0x45, 0x55, 0x36, 0x30, 0x30, 0x32, 0x36, 0x30}; // vin 10 to 17 hex to accii EU600260 byte data6[] = {0x00, 0x00, 0x00, 0x00, 0x35, 0x00, 0xA3, 0x01}; // Engine_Information_1_LS byte data7[] = {0x01, 0x01, 0xCF, 0x8D, 0x00, 0x55, 0x06, 0x6D}; // Engine_Information_2_LS byte data8[] = {0x50, 0x00, 0x79, 0x00, 0x00, 0x00, 0x06, 0xA5}; // Engine_Information_3_LS byte data9[] = {0x60, 0x60, 0x01, 0xF4}; // Wheel_Pulses byte data10[] = {0x02}; // System_Power_mode byte data11[] = {0x00, 0x2B, 0x00, 0x2B, 0x00, 0x2A, 0x00, 0x2A}; // Wheel_Grnd_Velocity_LS Power_Mode_Info_LS byte data12[] = {0x04, 0x03, 0x00}; // Power_Mode_info

// CAN RX Variables long unsigned int rxId; unsigned char len; unsigned char rxBuf[128];

// Serial Output String Buffer char msgString[128];

// CAN0 INT and CS

define CAN0_INT 2 // Set INT to pin 2

MCP_CAN CAN0(10); // Set CS to pin 10

void setup() { Serial.begin(115200); // CAN is running at 500,000BPS; 115,200BPS is SLOW, not FAST, thus 9600 is crippling.

// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled. if(CAN0.begin(MCP_ANY, CAN_33K3BPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!"); else Serial.println("Error Initializing MCP2515...");

// Since we do not set NORMAL mode, we are in loopback mode by default.//Changed from example JJ //CAN0.setMode(MCP_NORMAL);

pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input

Serial.println("Bosch CAN test..."); }

void loop() { if(millis() - prevTX >= invlTX) { // Send this at a one second interval. prevTX = millis();
byte sndStat0 = CAN0.sendMsgBuf(0x1101, 8, data0); // 101 command
byte sndStat1 = CAN0.sendMsgBuf(0x1621, 8, data1); //VNMF_LS_621_BCM

if(millis() - prevTX1 >= invlTX1) { // Send this at a one second interval. prevTX1 = millis();
byte sndStat2 = CAN0.sendMsgBuf(0x1624, 8, data2); //SW CAN $624 byte sndStat3 = CAN0.sendMsgBuf(0x162C, 8, data3); //VNMF_LS_62C_IPC CGM_LS IPC_LS } if(millis() - prevTX2 >= invlTX2) { // Send this at a one second interval. prevTX2 = millis();

byte sndStat4 = CAN0.sendMsgBuf(0x80EC4040, 8, data4); // vin 2 0to 9 hex to accii G6RS1E43   
byte sndStat5 = CAN0.sendMsgBuf(0x80EC8040, 8, data5); // vin 10 to 17 hex to accii EU600260

}

if(millis() - prevTX3 >= invlTX3) { // Send this at a one second interval. prevTX3 = millis();

byte sndStat6 = CAN0.sendMsgBuf(0x812CA040, 8, data6); // Engine_Information_1_LS
byte sndStat7 = CAN0.sendMsgBuf(0x812CC040, 8, data7); // Engine_Information_2_LS

}

if(millis() - prevTX4 >= invlTX4) { // Send this at a one second interval. prevTX4 = millis();

byte sndStat8 = CAN0.sendMsgBuf(0x802CE040, 8, data8); // Engine_Information_3_LS 
byte sndStat9 = CAN0.sendMsgBuf(0x8077C040, 4, data9);  // Wheel_Pulses

} if(millis() - prevTX5 >= invlTX5) { // Send this at a one second interval. prevTX5 = millis();

byte sndStat10 = CAN0.sendMsgBuf(0x80242040, 2, data10);  //System_Power_mode
byte sndStat11 = CAN0.sendMsgBuf(0x806B8040, 8, data11);  //Wheel_Grnd_Velocity_LS 
byte sndStat12 = CAN0.sendMsgBuf(0x80242040, 3, data12);  // Power_Mode_info

}

} if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read receive buffer { CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)

if((rxId & 0x80000000) == 0x80000000)             // Determine if ID is standard (11 bits) or extended (29 bits)
  sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
else
  sprintf(msgString, "Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);

Serial.print(msgString);

if((rxId & 0x40000000) == 0x40000000){            // Determine if message is a remote request frame.
  sprintf(msgString, " REMOTE REQUEST FRAME");
  Serial.print(msgString);
} else {
  for(byte i = 0; i<len; i++){
    sprintf(msgString, " 0x%.2X", rxBuf[i]);
    Serial.print(msgString);
  }
}

Serial.println();

}

}

/***** this is what I see in play back Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x006B8040 DLC: 8 Data: 0x00 0x2B 0x00 0x2B 0x00 0x2A 0x00 0x2A Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x00242040 DLC: 3 Data: 0x04 0x03 0x00 Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x00EC4040 DLC: 8 Data: 0x47 0x36 0x52 0x53 0x31 0x45 0x34 0x33 Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x00EC8040 DLC: 8 Data: 0x45 0x55 0x36 0x30 0x30 0x32 0x36 0x30 Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x006B8040 DLC: 8 Data: 0x00 0x2B 0x00 0x2B 0x00 0x2A 0x00 0x2A Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x00242040 DLC: 3 Data: 0x04 0x03 0x00 Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x012CA040 DLC: 8 Data: 0x00 0x00 0x00 0x00 0x35 0x00 0xA3 0x01 Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x012CC040 DLC: 8 Data: 0x01 0x01 0xCF 0x8D 0x00 0x55 0x06 0x6D Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x006B8040 DLC: 8 Data: 0x00 0x2B 0x00 0x2B 0x00 0x2A 0x00 0x2A Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x00242040 DLC: 3 Data: 0x04 0x03 0x00 Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x012CA040 DLC: 8 Data: 0x00 0x00 0x00 0x00 0x35 0x00 0xA3 0x01 Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x012CC040 DLC: 8 Data: 0x01 0x01 0xCF 0x8D 0x00 0x55 0x06 0x6D Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x006B8040 DLC: 8 Data: 0x00 0x2B 0x00 0x2B 0x00 0x2A 0x00 0x2A Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x00242040 DLC: 3 Data: 0x04 0x03 0x00 Standard ID: 0x101 DLC: 8 Data: 0xFE 0x02 0x10 0x02 0x00 0x00 0x00 0x00 Standard ID: 0x624 DLC: 8 Data: 0x00 0x20 0x00 0x00 0x00 0x00 0x00 0x00 Extended ID: 0x006B8040 DLC: 8 Data: 0x00 0x2B 0x00 0x2B 0x00 0x2A 0x00 0x2A Standard ID: 0x62C DLC: 8 Data: 0x00 0x40 0x00 0x00 0x00 0x00 0x00 0x00