I am working on a project with a Teensy 4.0, and I am using the FlexCan_T4 Arduino library for setting up a Canbus communication. I am also using two Innomaker Usb2Can: one used for sending a lot of messages in a very small interval of time(sends 1 message every 0ms, for 15k) (that are not read by the teensy thanks to the filter applyed on the Can-ID); the other one is used for sniffing all the messages and for send a single message with an id allowed by the teensy, to which it has to give a response back. The problem occurs is that, during the flow of all the other messages, the interval time between the read of that single message and the write of the response seems to be greater than when the flow is absent. Is there a way in order to speed-up the response back (without changing the baudrate) ? There is a 'writing timeout' that can be reduced ? thanks
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_1024, TX_SIZE_16> Can1;
CAN_message_t msg1;
void setup() {
Serial.begin(9600);
Can1.begin();
Can1.setBaudRate(125000); // default è 125k
Can1.setMaxMB(16);
Can1.setMB(MB10,RX,STD);
Can1.setMB(MB11,TX);
Can1.enableMBInterrupt(MB10);
Can1.onReceive(MB10, can1Sniff);
Can1.setMBFilter(REJECT_ALL);
Can1.setMBFilter(MB10, 0x7BC);
Can1.enhanceFilter(MB10);
Can1.distribute();
Serial.println("comm ok");
}
void loop() {
}
void can1Sniff(const CAN_message_t &msg) {
Serial.println("Ricevo da CAN1:");
Serial.print(" LEN: "); Serial.print(msg.len);
Serial.print(" COB-ID: "); Serial.print(msg.id, HEX);
Serial.print(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
msg1.id = 0x03 << 9 | 0x05 << 6 | 0x3f;
msg1.len = 6;
msg1.flags.remote = 0;
msg1.buf[0] = 0x3c;
msg1.buf[1] = 0xCB;
msg1.buf[2] = 0x00;
msg1.buf[3] = 0x00;
msg1.buf[4] = 0x05;
msg1.buf[5] = 0x00;
Can1.write(MB11,msg1);
}