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:
The receive side:
I hope someone has a solution for this problem.
Osiris
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