Hello all,
I'm currently using a Teesny 4.0 and have a jumper cable connected from
pin 23 (CAN RX1) to
pin 22 (CAN TX1) (Screenshot:
https://github.com/martovens/Testing_FlexCAN_T4/blob/main/Screenshot 2022-03-26 232112.jpg). I've been unable to get this working. I'm using FlexCAN_T4 by tonton81 at commit # ef2a838b8c35b8fd8a7a0ee7a85a615a18335127. I am also programming the Teensy 4.0 using PlatformIO on Visual Studio Code. Here is my code:
Code:
#include <Arduino.h>
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
CAN_message_t readFrame;
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(" Buffer: ");
for ( uint8_t i = 0; i < msg.len; i++ ) {
Serial.print(msg.buf[i], HEX); Serial.print(" ");
} Serial.println();
}
void setup()
{
Serial.begin(9600);
can1.begin();
can1.setBaudRate(9600);
can1.onReceive(canSniff);
can1.enableFIFO();
}
void canTX()
{
CAN_message_t msg;
msg.id = 0x7E0;
msg.buf[0] = 1;
msg.buf[1] = 2;
msg.buf[2] = 3;
msg.buf[3] = 4;
msg.buf[4] = 5;
msg.buf[5] = 6;
msg.buf[6] = 7;
msg.buf[7] = 8;
msg.len = 8;
msg.flags.extended = 0;
msg.flags.remote = 0;
can1.write(msg);
}
void loop(){
can1.events();
canTX();
can1.read(readFrame);
canSniff(readFrame);
can1.mailboxStatus();
digitalWrite(13, HIGH);
}
Here is the printout from running the code:
MB 0 OVERRUN: 0 LEN: 8 EXT: 0 TS: 0 ID: 0 Buffer: 0 0 0 0 0 0 0 0
FIFO Enabled --> Interrupt Disabled
FIFO Filters in use: 8
Remaining Mailboxes: 8
MB8 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB9 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB10 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB11 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB12 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB13 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB14 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
MB15 code: TX_DATA (Transmitting)(Standard Frame)(ID: 0x7E0)(Payload: 1 2 3 4 5 6 7 8)
I've also tried commenting out the can1.read(readFrame), canSniff(readFrame), and can1.mailboxStatus() statements in the loop(), and nothing prints out. I'm not sure what I'm doing wrong here, I've been scouring through this and other forums as well as projects that use FlexCAN_T4 but I still cannot get this to work.