CAN Bus Not working Teensy4.1

Dimitri

Well-known member
Hi All,

Working with a Teensy 4.1, I have done a multitude of CAN projects with Arduino Uno and Arduino Due in the past.


I am trying to get a Hello-World project up and running for CAN bus, however I am not getting any tangible output. Before I try any CAN-FD, I wanted to make sure I could get standard CAN2.0 working. I figure there's probably just something small that I am missing, figured someone here may be able to see if there's some glaring error in my code.

In the below code, I send the same message out on CAN1 and CAN2. With an o-scope, I probe the Tx/Rx pins of the Teensy, I get the following:

- CAN Rx2 (pin 0): Rests at GND
- CAN Tx2 (pin 1): Flatline at 3.3V
- CAN Rx1 (pin 23): Flatline at 3.3V
- CAN Tx1 (pin 22): Rests at 3.3with a series of small voltage spikes (3.3V to GND) every 3ms. The pulses within the series are spaced ~50µs. These blips occur for ~800µs.

In addition to my o-scope, I feed CAN1 lines to an MCP2561 CAN transceiver which then goes to an automotive CAN tool. I see no CAN traffic come up on my PC screen.

Any Ideas? I'm basing this Hello-World project on examples given by in the environment and from online distributors.

Thanks!
Code:
#include <FlexCAN_T4.h>

const byte pinOut_LED = 13;
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
CAN_message_t msg;

unsigned long t1,t2;

///////////////////////////////////////////////////////////////////////////////////////////////
void setup(void) 
{
  pinMode(pinOut_LED,OUTPUT);
  digitalWrite(pinOut_LED,HIGH);
  Serial.begin(115200);
  can1.begin();
  can1.setBaudRate(500000);
  can2.begin();
  can2.setBaudRate(500000);
  
  msg.id = 0x123;
  msg.buf[0] = 0x01;
  msg.buf[1] = 0x23;
  msg.buf[2] = 0x45;
  msg.buf[3] = 0x67;
  msg.buf[4] = 0x89;
  msg.buf[5] = 0xAB;
  msg.buf[6] = 0xCD;
  msg.buf[7] = 0xEF;

  t1 = millis();
  t2 = t1;
}
///////////////////////////////////////////////////////////////////////////////////////////////

void loop() 
{
  t1 = millis();

  if((t1-t2) >= 100)
  {
    can1.write(msg);
    delay(5);
    can2.write(msg);
    t2 = t1;
  }
 
}
 
How can your PC serial monitor see traffic if:
A) you have no callback
B) you're not polling
C) you are not using interrupts.

Sending may be working but you will never receive anything. Take a look at one of the examples (FIFO with interrupts) and make sure you are using the proper bus for the pins you have the transceiver connected to

You cant just put a CAN tool alone on teensy. On a vehicle the bus is terminated.
Is the line between teensy and you're tool properly terminated? 120ohm resistor at both furthest nodes. If the bus isn't terminated properly don't expect 500kbps to work at all. You may get away with 125kbps or below without termination but that's iffy
 
Hi Tonton81,

I have an external CAN tool that I use to read CAN bus, terminated properly with selectable 120Ω or 60Ω (or none). My PC is running the software that controls this external CAN tool.



Hi cgeber24,

I thought I had left a reply below my initial comment, it appears that it did not post though! I did not supply the MCP2561 with 5.0V, I instead did so with 3.3V. I figured this would be a problem, so I have replaced it with SN65HVD230 from Texas Instruments. It is not an FD transceiver, but that is OK for what I am doing.

Now, all I see on on CAN1_Tx and CAN1_Rx are pulses that occur every ~55µs, Hightime = 45µs, Lowtime = 10µs (imagine a duty cycle = 82%)


Any Ideas?
 
Hi All,

I got it all working. I forgot that you needed a functioning transceiver properly connected, before the µC would actually send out packaged CAN data.


Thank You!
 
Back
Top