CAN-FD configuration options

andnate

Member
Hi all,
I'm trying to get CAN FD working on a T4.1 and having trouble getting above 2Mbps. Initially I was getting garbled data at 2Mbps, but I tried bumping config.sample from 70 to 75 as I saw in an example in this thread and now have a good connection. Now I'm trying to push to 4 or 5Mbps and not getting anything at all on the other end. In that thread someone said that at or above 5Mbps, config.clock needs to be set to CLK_60MHz, but that didn't help. In fact, I can't get anything but CLK_24MHz to work at 2Mbps.
Are these configuration options documented anywhere? I have no idea what I'm changing or what values to try.

Here's my setup code:
Code:
  Can3FD.begin();
  CANFD_timings_t config;
  config.clock = CLK_40MHz;
  config.baudrate = 500000;
  config.baudrateFD = 4000000;
  config.propdelay = 190;
  config.bus_length = 1;
  config.sample = 75;   // 75 worked at 2mbps
  Can3FD.setBaudRate(config);
  Can3FD.setMaxMB(2);
  Can3FD.setMB(MB0,TX,STD);
  Can3FD.setMB(MB1,RX,STD);
  Can3FD.setMBFilter(REJECT_ALL);
  Can3FD.enableMBInterrupts();
  Can3FD.setMBFilter(MB0, messageID);
  Can3FD.setMBFilter(MB1, messageID+1);
  Can3FD.onReceive(MB1, Can3Int);
  Can3FD.mailboxStatus();

And my message sending:
Code:
void loop() {
  for (int i = 1; i < 255; i++) {
    CAN_message_t msg;
    msg.id = messageID+1;        // Arbitrary CAN ID
    msg.len = 8;           // Standard length
    for (int j = 1; j < 8; j++) {
      msg.buf[j] = 0xAA;      // Fill the message with sample data
    }
    msg.buf[0] = i;
    // Send the message
    #ifdef TX_CAN1
      Can1.write(msg);
    #endif
    #ifdef TX_CAN2
      Can2.write(msg);
    #endif
    #ifdef TX_CAN3
      CANFD_message_t FDmsg;
      FDmsg.id = messageID+2;
      FDmsg.len = 8;
      for (int k = 1; k < 8; k++) {
        FDmsg.buf[k] = 0xAA;      // Fill the message with sample data
      }
      FDmsg.buf[0] = i;
      Can3FD.write(FDmsg);
    #endif
    delay(100);
  }
  delay(5000);
}
 
You're setting propagation delay which is good. I failed to do this and had nothing but trouble. But, the thing is, at FD speeds, you need your propagation delay to be pretty accurate or you will get bit errors. You might try tweaking the value up and down to see if it helps.

Here is what it means: When you send CAN traffic you are sending on the TX pin and it expects to receive the bits back on the RX pin because everyone on the bus receives all traffic, even if you're the one sending it. The propagation delay is important because if you send fast enough, when you read the bus to get the RX bits you will be reading a different bit from the one you want to read. The signal literally is still propagating over the wire. So, you mess with that setting until you are actually reading the bits it expects. Then things start to magically work.

That was my problem, doesn't mean it is your problem. I believe I did use a value of 190 so you're already there but see if you need to tweak it. One way to tell would be to scope RX and TX pins and see what the actual propagation delay is.
 
I can get 5Mb/s to work with these settings:
Code:
  CANFD_timings_t config;
  config.clock = CLK_60MHz;
  config.baudrate =   500000;
  config.baudrateFD = 5000000;
  config.propdelay = 188;
  config.bus_length = 1;
  config.sample = 75;

1739877328497.png


You might want to try 4 or 6Mb/s instead. I found they are more reliable then 5Mb/s.
 
what are propdelay and bus_length actually specifying? Should there be some physical value that I could measure and put in there?
 
Back
Top