Closed la09k closed 3 years ago
Hi, the define isn't used anywhere. Look into the .cpp, id is defined as uint32_t. So 29-bit identifier should work if MCP-CAN supports it.
Yes, I indeed observed that; and yes MCP does support extended CAN. The thing is while trying with a 29-bit identifier, the received data buffer is empty. I first kept the ID as 0x7FF and received 12 bytes data in the receiver end. When simply changing to ID 0x18263598, the received data buffer comes out to be empty!
Did you try it with MCP_CAN only? Does it work there? I can't find a reason why it shouldn't work here. All IDs are uint32_t in my code and only uses when communicating with MCP_CAN. From MCP_CAN example: if((rxId & 0x80000000) == 0x80000000) // Determine if ID is standard (11 bits) or extended (29 bits). Your Test-ID & 0x80000000 == 0 -> not extended CAN. Maybe that's the reason.
Yes, that should be the reason. "To mark the ID as extended, OR the ID with 0x80000000. To send a remote request, OR the ID with 0x40000000. "
Nope, didn't work even after changing ID to 0x801F456. Also, ORed the ID with 0x80000000. Here's my test code:
Sender:
MCP_CAN CAN0(10); IsoTp isotp(&CAN0,MCP_INT);
struct Message_t TxMsg, RxMsg;
uint32_t can_tx = 0x8801F456;
//uint32_t can_tx =0x7FF; //long unsigned int can_tx = 0x18263598;
byte data1[] = {0x09, 0x60, 0x01, 0x90, 0x1F, 0x40, 0x03, 0x20, 0xC8, 0x02, 0x58, 0x02};
void setup() { Serial.begin(115200); pinMode(MCP_INT, INPUT); CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ); CAN0.setMode(MCP_NORMAL); TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t)); }
void loop() { TxMsg.len=sizeof(data1); //TxMsg.tx_id=can_tx; TxMsg.tx_id=(can_tx|0x80000000); memcpy(TxMsg.Buffer,data1,(sizeof(data1))); Serial.println(F("Send...")); isotp.print_buffer(TxMsg.tx_id, TxMsg.Buffer, TxMsg.len); isotp.send(&TxMsg); }
Receiver:
MCP_CAN CAN0(10); IsoTp isotp(&CAN0,MCP_INT);
struct Message_t TxMsg, RxMsg;
uint32_t can_rx = 0x8801F456;
//uint32_t can_rx = 0x7FF; //long unsigned int can_rx = 0x18263598;
void setup() { Serial.begin(115200); pinMode(MCP_INT, INPUT); CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ); CAN0.setMode(MCP_NORMAL);
RxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t)); RxMsg.rx_id=(can_rx|0x80000000); //RxMsg.rx_id=can_rx;
}
void loop() { isotp.receive(&RxMsg); isotp.print_buffer(RxMsg.rx_id, RxMsg.Buffer, RxMsg.len); //Serial.println(RxMsg.Buffer[7]); }
It works perfectly well while sending the data with ID 0x7FF and without ORed with 0x80000000. The test code must be fine then and with the above adjustments, the extended id implementation can be expected right?
I am also trying to figure out anything missing from library functions in regard to this but didn't find anything wrong as of now.
Although the project description clearly states the implementation being for 11-bit standard CAN messages, I wanted to get an insight into its usage for Extended CAN messages with 29-bit identifier. In the header file, macro CAN_MAX_DLEN holds value 8 (commented as "Not extended CAN"). Could you kindly elaborate on what changes are expected in the library files for updating to 29-bit identifier support? It would be of immense help!