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!
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;
}
}