Hi all i am still relative new and inexperience to arduino and CAN bus shields, i have download the latest program from the wiki website, however i am still unable to receive message from the 1st can bus shield. inbetween the connection of CANL to CANL and CANH to CANH, do i need a 120ohm resistor?
try the latest code, github.com/reeedstudio/CAN_BUS_Shield
actually I can’t sure if the code in wiki is latest.
Hi thanks for the reply. The code is correct, is just that i forget to add a 120ohm resistor between CANH and CANL.
That… makes me even more comfortable with the bug I found… I wonder if its already been fixed. It has to do with receiving extended message IDs greater than 0x00007FFF.
The code you linked to still has the culprit code causing my issue.
I discovered the bit math of function mpc2515_read_id() in mpc_can.cpp produces odd results as its written, and this was across two different boards.
This is part of the original code:
*id <<= 16; *id = *id +(tbufdata[MCP_EID8]<<8) + tbufdata[MCP_EID0];
I’m sending an extended frame with 0x1FFFFFFF as the ID.
The code would shift 16 bits to the left and print 1FFF0000.
The second line would be shifted and summed up correctly, except somehow it subtracts 0x00010000 from the 0x1FFF0000 value before FFFF is added.
I would be left with a false received ID of 0x1FFEFFFF.
This occurs as long as the most significant bit of tbufdata[MCP_EID8] is set. (eg 0x00008000)
My change, overwriting the above lines:
*id = (*id<<8) + tbufdata[MCP_EID8]; *id = (*id<<8) + tbufdata[MCP_EID0];
There should be two 120Ω terminating resistors, one on each end of the CAN bus.