Error receiving FlexCAN_T4 message

qwqwqeqe

New member
I am trying to send&receive CAN message using 2 teensy4.1.
I checked sending device message normally. But receiving device cannot receive can message.
Please tell me if you have any idea. Thank you.
Here is my codes.

Sending device

Code:
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;

void setup(void) {
  Serial.begin(115200); delay(400);
  pinMode(34, OUTPUT); digitalWrite(34, LOW); /* optional tranceiver enable pin */
  Can0.begin();
  Can0.setBaudRate(500000);
}



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 loop() {
  Can0.events();
  static uint32_t timeout = millis();
  if ( millis() - timeout > 200 ) {
    CAN_message_t msg;
    msg.id = random(0x1,0x7FE);
    for ( uint8_t i = 0; i < 8; i++ ) msg.buf[i] = i + 1;
    Can0.write(msg);
    timeout = millis();
  }
}

Reading device

Code:
#include <FlexCAN_T4.h>

FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
//FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
CAN_message_t msg;


#define pinin 8
#define pinout 9

void setup() {

  pinMode(34,OUTPUT);
  digitalWrite(34,LOW);
  pinMode(pinout, OUTPUT);
  pinMode(pinin, INPUT);
  Serial.begin(115200);
  can1.begin();
  can1.setBaudRate(500000);
    can1.enableFIFO();
  can1.enableFIFOInterrupt();
}

void loop() {

if ( can1.read(msg) ) {
    Serial.print("CAN1 "); 
    Serial.print("MB: "); Serial.print(msg.mb);
    Serial.print("  ID: 0x"); Serial.print(msg.id, HEX );
    Serial.print("  EXT: "); Serial.print(msg.flags.extended );
    Serial.print("  LEN: "); Serial.print(msg.len);
    Serial.print(" DATA: ");
    for ( uint8_t i = 0; i < 8; i++ ) {
      Serial.print(msg.buf[i]); Serial.print(" ");
    }
    Serial.print("  TS: "); Serial.println(msg.timestamp);
  }
}


Here is my pin connection image

KakaoTalk_20230210_150743220.jpg
 
If it's the board I think it is, there is a solder jumper on bottom labeled SJ7 that needs soldered on both boards.

For the receiving code, you EnableFIFOInterrupt() but don't attach a function or service the interrupt. Try just commenting out that line.
 
Back
Top