FlexCAN_T4 TX_INACTIVE

Osiris

Member
Hello,

I am using 2x Teensy 4.0 for CANbus. With the use of FIFO everything works correct. When I try to use mailboxes the send-side does not send data (or the receive side does not receive data). If I use Can2.mailboxStatus() on the send-side I get this result:

FIFO Disabled
Mailboxes:
MB0 code: RX_EMPTY (Standard Frame)
MB1 code: TX_INACTIVE
MB2 code: RX_EMPTY (Standard Frame)
MB3 code: RX_EMPTY (Standard Frame)

Seems to me that it should be : MB1 code: TX_DATA (Transmitting)

The send side:
Code:
#include <elapsedMillis.h>
#include <FlexCAN_T4.h>

FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can2;

byte sendByte[8]    = {0,0,0,0,0,0,0,0} ;

float F_tempTeensy40board;
uint16_t I_tempTeensy40board;
elapsedMillis tempTimer;

void setup()

 {
   Serial.begin(9600);               
 
   Can2.begin();
   Can2.setClock(CLK_24MHz);       
   Can2.setBaudRate(1000000);     
   Can2.setMaxMB(4);             
   Can2.enableMBInterrupts();     
   Can2.setMB(MB1, TX, STD);       
      
   //Can2.onTransmit(MB1,  sendData );
    
   Can2.mailboxStatus();
 
  }


 void sendData( )
  {   
   Can2.events();
   CAN_message_t msg;
   msg.len = 8;
   msg.id = 0x01;
   msg.buf[0] = sendByte[0];
   msg.buf[1] = sendByte[1];
   msg.buf[2] = sendByte[2];
   msg.buf[3] = sendByte[3];
   msg.buf[4] = sendByte[4];
   msg.buf[5] = sendByte[5];
   msg.buf[6] = sendByte[6];
   msg.buf[7] = sendByte[7];
   Can2.write(MB1, msg);
  
  }     

void loop()
 {
   if( tempTimer >= 15000 )      // 15 seconds
    {
     F_tempTeensy40board = 10 * tempmonGetTemp();
     I_tempTeensy40board = F_tempTeensy40board;   
    
     sendByte[6] = highByte(I_tempTeensy40board);
     sendByte[7] =  lowByte(I_tempTeensy40board);
        
     sendData();
     tempTimer = 0;
    }
        
  }

The receive side:
Code:
#include <FlexCAN_T4.h>

FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can2;

void setup()

 {
   Serial.begin(9600);               
    
   Can2.begin();
   Can2.setClock(CLK_24MHz);       
   Can2.setBaudRate(1000000);       
   Can2.setMaxMB(4);                                                   
   Can2.enableMBInterrupts();       
   Can2.setMB(MB1, RX, STD);         
   Can2.setMBFilter(MB1,  0x01);   
   Can2.onReceive(MB1,  canSniff); 
    
   Can2.mailboxStatus();

   }



 void canSniff(const CAN_message_t &msg)
 {
   Serial.print("MB "); Serial.print(msg.mb);
   Serial.print(" | OVERRUN: "); Serial.print(msg.flags.overrun);
   Serial.print(" | LEN: "); Serial.print(msg.len);
   Serial.print(" | EXT: "); Serial.print(msg.flags.extended);
   Serial.print(" | TS: "); Serial.print(msg.timestamp);
   Serial.print(" | ID: "); Serial.print(msg.id, HEX);
   Serial.print(" | BUS: "); Serial.print(msg.bus);
   Serial.print(" | Buffer: ");
      
   for ( byte i = 0; i < msg.len; i++ )
    {
     Serial.print(msg.buf[i], HEX); Serial.print(" ");
    }
   Serial.println(); Serial.println();
  }


void loop()
 {
    
 }


I hope someone has a solution for this problem.

Osiris
 
From https://github.com/tonton81/FlexCAN_T4

"Events must be used in the loop(), IntervalTimer, or teensyThreads, for the callback system to push received interrupt frames from the queue to the callback. Sequential frames are pushed out from there as well, we'll talk about that soon."

I used the sendData() with FIFO and it worked great. Removed the sendData() and moved it to void loop() but it still the message TX_INACTIVE.


Can2.mailboxStatus() tells me MB1 TX_INACTIVE. The function is called in the setup. This needs to be solved first.
 
On the send-side I placed Can2.enableMBInterrupts() after the settings of the mailbox. The correct order is:

Can2.setMaxMB(4);
Can2.setMB(MB1, TX, STD);
Can2.enableMBInterrupts();

Moved Can2.mailboxStatus() from the setup to the end of void sendData().

now I get:
FIFO Disabled
Mailboxes:
MB0 code: RX_EMPTY (Standard Frame)
MB1 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x1)(Payload: 0 0 0 0 0 0 2 67)
MB2 code: RX_EMPTY (Standard Frame)
MB3 code: RX_EMPTY (Standard Frame)
:)

The receive-side did not function either.
1) Moved Can2.mailboxStatus() from the setup to the end of void cansniff().
2) Moved the Can2.enableMBInterrupts() after the Can2.onReceive(MB1, canSniff), but that did not help.
3) Changed Can2.enableMBInterrupts() to Can2.enableMBInterrupt(MB1) and data appeared on the serial monitor.

The correct order is:
Can2.setMaxMB(4);
Can2.setMB(MB1, RX, STD);
Can2.setMBFilter(MB1, 0x1);
Can2.onReceive(MB1, canSniff);
Can2.enableMBInterrupt(MB1);

Now I get :
MB 1 | OVERRUN: 0 | LEN: 8 | EXT: 0 | TS: 17873 | ID: 1 | BUS: 2 | Buffer: 0 0 0 0 0 0 2 12

FIFO Disabled
Mailboxes:
MB0 code: RX_FULL
MB1 code: RX_EMPTY (Standard Frame)
MB2 code: RX_EMPTY (Standard Frame)
MB3 code: RX_EMPTY (Standard Frame)

The problem is solved. :)

Osiris
 
Back
Top