Issue with CAN communication between Arduino Nano and Teensy 4.1

Hi, I am trying to do CAN communication between Teensy 4.1 and Arduino Nano. For the communication between the Teensy and Nano, I am using a TJA1050 transceiver on Teensy side and MCP2515 CAN module on the Nano side. I am able to do CAN communication between two Nano using MCP2515, so I know that my mcp2515 is working properly.

When I am sending the data, it shows that the data is being sent from Teensy, but it stops sending data after 17 iterations and also the Arduino Nano is not receiving any data. I also tried setting the same bit rate but could not see anything being received on the Nano. I have used ACAN_T4 and and ACAN2515 libraries.

Code for Teensy 4.1

#ifndef __IMXRT1062__
#error "This sketch should be compiled for Teensy 4.x"
#endif

//-----------------------------------------------------------------

#include <ACAN_T4.h>

//-----------------------------------------------------------------

void setup () {
  pinMode (LED_BUILTIN, OUTPUT) ;
  Serial.begin (9600) ;
  while (!Serial) {
    delay (50) ;
    digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
  }
  ACAN_T4_Settings settings (125 * 1000) ; // 125 kbit/s
  // settings.mBitRatePrescaler = 6;
  //settings.mPropagationSegment = 5;
  //settings.mPhaseSegment1 = 5;
  //settings.mPhaseSegment2 = 5;
  const uint32_t errorCode = ACAN_T4::can1.begin (settings) ;
  Serial.print ("Bitrate prescaler: ") ;
  Serial.println (settings.mBitRatePrescaler) ;
  Serial.print ("Propagation Segment: ") ;
  Serial.println (settings.mPropagationSegment) ;
  Serial.print ("Phase segment 1: ") ;
  Serial.println (settings.mPhaseSegment1) ;
  Serial.print ("Phase segment 2: ") ;
  Serial.println (settings.mPhaseSegment2) ;
  Serial.print ("RJW: ") ;
  Serial.println (settings.mRJW) ;
  Serial.print ("Triple Sampling: ") ;
  Serial.println (settings.mTripleSampling ? "yes" : "no") ;
  Serial.print ("Actual bitrate: ") ;
  Serial.print (settings.actualBitRate ()) ;
  Serial.println (" bit/s") ;
  Serial.print ("Exact bitrate ? ") ;
  Serial.println (settings.exactBitRate () ? "yes" : "no") ;
  Serial.print ("Distance from wished bitrate: ") ;
  Serial.print (settings.ppmFromWishedBitRate ()) ;
  Serial.println (" ppm") ;
  Serial.print ("Sample point: ") ;
  Serial.print (settings.samplePointFromBitStart ()) ;
  Serial.println ("%") ;
  if (0 == errorCode) {
    Serial.println ("can1 ok") ;
  } else {
    Serial.print ("Error can1: 0x") ;
    Serial.println (errorCode, HEX) ;
    while (1) {
      delay (100) ;
      Serial.println ("Invalid setting") ;
      digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
    }
  }
}

//-----------------------------------------------------------------

static uint32_t gSendDate = 0 ;
static uint32_t gSentCount = 0 ;

//-----------------------------------------------------------------

void loop () {
  CANMessage message ;
  message.len = 8;
  message.data[0] = 127;
  message.data[1] = 43;
  message.data[2] = 1;
  if (gSendDate <= millis ()) {
    //message.id = 0x542 ;
    const bool ok = ACAN_T4::can1.tryToSend (message) ;
    if (ok) {
      gSendDate += 2000 ;
      gSentCount += 1 ;
      Serial.print ("Sent: ") ;
      Serial.println (gSentCount) ;
    }
  }
}

Code for Arduino Nano

#include <ACAN2515.h>

// Error codes and possible causes:
//    In case you see "Configuration error 0x1", the Arduino doesn't communicate
//       with the 2515. You will get this error if there is no CAN shield or if
//       the CS pin is incorrect.
//    In case you see succes up to "Sent: 17" and from then on "Send failure":
//       There is a problem with the interrupt. Check if correct pin is configured
//——————————————————————————————————————————————————————————————————————————————

static const byte MCP2515_CS  = 10 ; // CS input of MCP2515 (adapt to your design)
static const byte MCP2515_INT =  3 ; // INT output of MCP2515 (adapt to your design)

//——————————————————————————————————————————————————————————————————————————————
//  MCP2515 Driver object
//——————————————————————————————————————————————————————————————————————————————

ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ;

//——————————————————————————————————————————————————————————————————————————————
//  MCP2515 Quartz: adapt to your design
//——————————————————————————————————————————————————————————————————————————————

static const uint32_t QUARTZ_FREQUENCY = 16UL * 1000UL * 1000UL ; // 16 MHz

void setup () {
  //--- Switch on builtin led
  pinMode (LED_BUILTIN, OUTPUT) ;
  digitalWrite (LED_BUILTIN, HIGH) ;
  //--- Start serial
  Serial.begin (9600) ;
  //--- Wait for serial (blink led at 10 Hz during waiting)
  while (!Serial) {
    delay (50) ;
    digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
  }
  //--- Begin SPI
  SPI.begin () ;
  //--- Configure ACAN2515
  Serial.println ("Configure ACAN2515") ;
  ACAN2515Settings settings (QUARTZ_FREQUENCY, 125UL * 1000UL) ; // CAN bit rate 125 kb/s
  settings.mRequestedMode = ACAN2515Settings::NormalMode ; // Select normal mode
  const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ;
  if (errorCode == 0) {
    Serial.print ("Bit Rate prescaler: ") ;
    Serial.println (settings.mBitRatePrescaler) ;
    Serial.print ("Propagation Segment: ") ;
    Serial.println (settings.mPropagationSegment) ;
    Serial.print ("Phase segment 1: ") ;
    Serial.println (settings.mPhaseSegment1) ;
    Serial.print ("Phase segment 2: ") ;
    Serial.println (settings.mPhaseSegment2) ;
    Serial.print ("SJW: ") ;
    Serial.println (settings.mSJW) ;
    Serial.print ("Triple Sampling: ") ;
    Serial.println (settings.mTripleSampling ? "yes" : "no") ;
    Serial.print ("Actual bit rate: ") ;
    Serial.print (settings.actualBitRate ()) ;
    Serial.println (" bit/s") ;
    Serial.print ("Exact bit rate ? ") ;
    Serial.println (settings.exactBitRate () ? "yes" : "no") ;
    Serial.print ("Sample point: ") ;
    Serial.print (settings.samplePointFromBitStart ()) ;
    Serial.println ("%") ;
  } else {
    Serial.print ("Configuration error 0x") ;
    Serial.println (errorCode, HEX) ;
  }
}

//----------------------------------------------------------------------------------------------------------------------

static uint32_t gReceivedFrameCount = 0 ;

//——————————————————————————————————————————————————————————————————————————————

void loop () {
  CANMessage frame ;

  if (can.available ()) {
    can.receive (frame) ;
    int pwm = frame.data[0];
    int angle = frame.data[1];
    int dir = frame.data[2];
    gReceivedFrameCount ++ ;
    Serial.print ("Received: ") ;
    Serial.print (gReceivedFrameCount) ;
    Serial.print("  pwm ");
    Serial.print(pwm);
    Serial.print("  angle ");
    Serial.print(angle);
    Serial.print("  dir ");
    Serial.println(dir);
  }
}

If you can help me out with this problem, it will be a great help. Thank you.

Does an oscilloscope show any activity on the CAN bus?
Post a link to a photo showing the wiring connections and pin numbers.
Are the MCP2515 adaptors using 8 or 16 MHz crystals?

MCP2515 is using 8MHZ crystal. I do not have an oscilloscope.
The connections are given below
image

The interrupt pin number on the Nano is 3. CRX and CTX are 23 and 22 on Teensy 4.1

Try setting the frequency in your nano sketch to 8 MHz.

It is not clear from your image. Do you have two 120Ohm termination resistors on your bus? Some CAN module have them on the board often with a jumper to disable it when more than two modules are used. There should be one resistor on each end.

It is a useful tool to have. Any cheap old analog oscilloscope would do it for CAN.

Yes, I do have the terminating resistors at both end.

Yeah I am thinking of buying it.

Tried that too but nothing happened. Do you know if MCP2515 and TJA1050 transceiver are compatible. I could not find anything regarding that. But the MCP2515 can controller module has a TJA1050 transceiver so I think they should be compatible but not sure.

The documentation for the Teensy talks about there being 3 CAN controllers on-board.
In the absence of an oscilloscope perhaps you could use one of the other on-board controllers (with driver) to monitor the output.

Yes, I have some modules with the MCP2515 and the TJA1050 as well. I looked at the TJA 1050 datasheet and did not see a reason why they would not be compatible.

The datasheet shows there is a pin called S. It should be connected to GND. If connected to Vcc the transceiver will go into silent mode.

Yes it worked for 8 MHZ. Thank you so much.
In the example that they have given uses 16MHZ so I was also using the same. Also when I did CAN communication between the two Nano boards I had used 16MHZ frequency and it was working so I didn't realize that it might not be same case when communicating with Teensy 4.1.
Thank you so much for the help.