FlexCAN_T4 - FlexCAN for Teensy 4

Your sketch does not transmit any CAN frame. You have not setup the mailbox correctly.

Follow the example sketch : mailbox_filtering_example_with_interrupts.ino

Code:
Can0.begin();
  Can0.setBaudRate(250000);
  Can0.setMaxMB(NUM_TX_MAILBOXES + NUM_RX_MAILBOXES);
  for (int i = 0; i<NUM_RX_MAILBOXES; i++){
    Can0.setMB((FLEXCAN_MAILBOX)i,RX,EXT);
  }
  for (int i = NUM_RX_MAILBOXES; i<(NUM_TX_MAILBOXES + NUM_RX_MAILBOXES); i++){
    Can0.setMB((FLEXCAN_MAILBOX)i,TX,EXT);
  }
  Can0.setMBFilter(REJECT_ALL);
  Can0.enableMBInterrupts();
  Can0.onReceive(MB0,canSniff);
  Can0.onReceive(MB1,canSniff);
  Can0.onReceive(MB2,canSniff);
  Can0.setMBUserFilter(MB0,0x00,0xFF);
  Can0.setMBUserFilter(MB1,0x03,0xFF);
  Can0.setMBUserFilter(MB2,0x0B,0xFF);
  Can0.mailboxStatus();

Change Can0 to your can2
 
Your sketch does not transmit any CAN frame. You have not setup the mailbox correctly.

Follow the example sketch : mailbox_filtering_example_with_interrupts.ino

Code:
Can0.begin();
  Can0.setBaudRate(250000);
  Can0.setMaxMB(NUM_TX_MAILBOXES + NUM_RX_MAILBOXES);
  for (int i = 0; i<NUM_RX_MAILBOXES; i++){
    Can0.setMB((FLEXCAN_MAILBOX)i,RX,EXT);
  }
  for (int i = NUM_RX_MAILBOXES; i<(NUM_TX_MAILBOXES + NUM_RX_MAILBOXES); i++){
    Can0.setMB((FLEXCAN_MAILBOX)i,TX,EXT);
  }
  Can0.setMBFilter(REJECT_ALL);
  Can0.enableMBInterrupts();
  Can0.onReceive(MB0,canSniff);
  Can0.onReceive(MB1,canSniff);
  Can0.onReceive(MB2,canSniff);
  Can0.setMBUserFilter(MB0,0x00,0xFF);
  Can0.setMBUserFilter(MB1,0x03,0xFF);
  Can0.setMBUserFilter(MB2,0x0B,0xFF);
  Can0.mailboxStatus();

Change Can0 to your can2
I am struggling to understand how I have setup the mailboxes incorrectly?
On can1 I have setup a single mailbox to recieve messages and it will trigger canSniff on receive.
On can2 I have setup a single mailbox to transmit messages.

You can see these two mailboxes setup in the serial output in my last message.

Even when I hookup a cansniffer box to can2 directly (all the correct 120ohm terminations of course) it still doesn't transmit from the mailbox.

The message is stuck in the mailbox and won't transmit properly, from what I've read this is because it is not getting an ACK but both the cansniffer box and can1 should be able to ACK this.
 
Hello, Im having issues with setting a filter for my CANBus. Ideally, I give my motors a desiredVelocity/Position, and the motor will return a ActualVelocity/Position (encoder feedback). I attempted to do this by setting the filter to be the API key (in hexidecimal) of the encoder feedback. However, the value im getting returned is the wrong API key. I am unsure why, dont know if im setting up CAN incorrectly or if the company APi documentation I bought the motors from is not up to date.
C++:
static constexpr uint32_t BASE = 0x0205B880;      // lower 6 bits = 0


void CANBus::CANBusInit(){
    can.begin();
    can.setRFFN(true);
    can.setClock(CLK_60MHz);
    can.setBaudRate(1000000);
    can.setFIFOFilter(REJECT_ALL);
    can.enableFIFO();
    can.enableFIFOInterrupt();
    for(int i = 1; i <= 8; i++){
        can.setFIFOFilter(i - 1, BASE | i, EXT, NONE);
    }
    can.onReceive(FIFO,canSniff);

    delay(2000);
}



void canSniff(const CAN_message_t &msg){
    if(msg.flags.extended != 1){    // checking if we are getting an extened message
        return;
    } else {
        steer_mb[2] = msg.id;   // if so check the CAN ID
        return;
    }
}

// this is what is getting returned "0205B808"
// instead of 0x0205B880;
 
Back
Top