I am using the CAN-BUS Shield with extended addresses. I found a little problem in function “mcp2515_read_id”. The CAN id is calculated incorrectly (caused by the casting of the unsigned chars). I solved this issue in this way. I hope this can help other users and will be updated in the library.
I made one function that also can be useful for someone. maybe it also can be added to library if you think it is ok.
regards,
/*********************************************************************************************************
** Function name: waitingForMsg
** Descriptions: Waiting for X time the message with the id
** input parameters: id : can id
timeout : time to wait
** Output parameters: *len : buf length
*buf : data buf
** Returned value: the status of the function
*********************************************************************************************************/
INT8U MCP_CAN::waitingForMsg(INT32U id, INT16U timeout, INT8U *len, INT8U *buffer)
{
INT32U start = millis();
while (millis() - start < timeout) {
if (checkReceive()==CAN_MSGAVAIL) {
readMsgBuf(len, buffer);
if ( id == m_nID ) {
return 1;
}
}
}
#if DEBUG_MODE
Serial.print("waitingForMsg TIMEOUT: ");
Serial.println(id,HEX);
#endif
*len = 0;
return 0;
}