[Metalab] CAN-Bus - debug advice?

overflo flo at tekstix.com
Tue Oct 5 10:08:28 CEST 2021


ohai


> Yes, I’m a CAN expert.  Ask me anything.


cool!

so i read there are different CAN standards.
CAN supports different bitrates and communication speeds.
i am dealing with a blackbox without documentation.


i got myself a MCP2515 (SPI interfaced CAN transceiver).
i can talk to it over SPI and i get SOME data on the CAN lines i am trying to debug.


the relevant callback-function to print that data looks like this:

void onReceiveBufferFull(uint32_t const timestamp_us, uint32_t const id, uint8_t const * data, uint8_t const len)
{
   Serial.print("[ ");
   Serial.print(timestamp_us);
   Serial.print("] ");

   Serial.print("ID");
   if(id & MCP2515::CAN_EFF_BITMASK) Serial.print("(EXT)");
   if(id & MCP2515::CAN_RTR_BITMASK) Serial.print("(RTR)");
   Serial.print(" ");
   Serial.print(id, HEX);

   Serial.print(" DATA[");
   Serial.print(len);
   Serial.print("] ");
   std::for_each(data,
                 data+len,
                 [](uint8_t const elem) {
                   Serial.print(elem, HEX);
                   Serial.print(" ");
                 });
   Serial.println();
}



some IDs have an EFF flag set, some not.
i dont know what that is yet.


here is some example raw data i captured.


[ 6615006]  ID(EXT) 9FFFADE0 DATA[0]
[ 6619811]  ID(EXT) 9FF5BC1F DATA[0]
[ 12934718] ID(EXT) 8B783EA0 DATA[0]
[ 48995318] ID(EXT) 9783EA00 DATA[0]
[ 57706446] ID(EXT) 983EA000 DATA[0]

[ 392002959] ID 200 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 392013566] ID 6DF DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 392018774] ID 188 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 392023796] ID 3C8 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC

[ 392028621] ID(EXT) 843C8DB7 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 392033812] ID(EXT) 8DB7C360 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 402711072] ID(EXT) 9B7C3600 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 404050719] ID(EXT) 97C36000 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC


[ 425640295] ID(EXT) 9C360000 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 425651260] ID(EXT) 80000DB7 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 425656204] ID(EXT) 80DB7DB7 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC

[ 425661425] ID 188 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC
[ 425666297] ID 6DF DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC

[ 425671443] ID(EXT) 96FEC3A0 DATA[12] 0 0 0 0 0 0 0 0 D3 92 5A AC


i initalize the transceiver like this:   mcp2515.setBitRate(CanBitRate::BR_250kBPS_16MHZ);

there are different modes to initalize it:

   BR_125kBPS_16MHZ  = 0,
   BR_250kBPS_16MHZ  = 1,
   BR_500kBPS_16MHZ  = 2,
   BR_1000kBPS_16MHZ = 3,
   BR_125kBPS_8MHZ  = 4,
   BR_250kBPS_8MHZ  = 5,
   BR_500kBPS_8MHZ  = 6,
   BR_1000kBPS_8MHZ = 7



Questions:
  - would i read ANY (wrong/different) data if i get the bitrate setting part wrong?
  - is there a reliable way to find out the correct bitrate used in the blackbox system?
  - what is a good way to debug the captured data
  - any recommendations for FOSS software (linux) ?
  - any recommendations on books/papers/videos worth reading/watching?

:*
-flo





More information about the Metalab mailing list