Search code examples
embedded-linuxloopbackcan-bus

Can-bus data has some bits always set to 0


I'm setting up the CAN-bus on a new custom board. It uses the mcp2515 controller connected via SPI-Bus. When receiving using 'candump' one bit in the data is always 0 (to be specific, the first bit off the data). The two other devices on the bus work perfectly.
Possibly related, there is a timing problem in the hardware, I have to set the baud-rate 20% higher to get the correct baud rate for the other devices.

This even happens if I disconnect the bus-cable and enable loopback!

#ip link set can0 type can bitrate 600000 loopback on
#ifconfig can0 up
#candump can0 &
# cansend can0 0FF#AABBCCDDEEFFFFFF
  can0  4FB   [8]  2A BB CC DD EE FF FF FF
  can0  0FF   [8]  AA BB CC DD EE FF FF FF
# cansend can0 0AB#AABBCCDDEEFFFFFF
  can0  4AB   [8]  2A BB CC DD EE FF FF FF
  can0  0AB   [8]  AA BB CC DD EE FF FF FF
# cansend can0 000#0000CCDDEEFFFFFF
  can0  400   [8]  00 00 4C DD EE FF FF FF
  can0  000   [8]  00 00 CC DD EE FF FF FF

Are there any obvious reasons why this could be happening?
Is it possible the timing error in the hardware causes this problem, even in loopback mode?

edit
removed example with a bad CAN_ID 'FFF' to reduce confusion


Solution

  • I managed to find solution to both problems:

    • The crystal was defines as 24 MHz but there was a 20 MHz build in. That explains, why I needed a 20% higher baud-rate to communicate.
    • The SPI-Bus had a wrong max-frequency. Somehow some of the first recieved ones where zero when reading the bus. With the correct settings the can-bus now works perfectly.