Hi All,
I working on an electronic dash project for my motorhome. The UI is built, and I now need to get it connected to the CANbus. So far I have failed utterly. I assume that it's due to ignorance on my part - something small but critical that I'm missing. Please help before I flush the whole thing...
Here's the setup:
I'm using example code I found online (below), and it seems to conform with what I see in the FlexCAN_T4 examples. The output delivered to the serial monitor looks like this:
can 1 begin complete
can 1 baud rate set
can 2 begin complete
can 2 baud rate set
can 3 begin complete
can 3 baud rate set
CAN1 read status = 0
CAN3 read status = 0
message sent, status = 1
CAN1 read status = 0
CAN3 read status = 0
message sent, status = 1
with the last 3 lines repeating infinitely.
Thanks in advance for any help!
Regards,
Randy
//**************************************************************************************************************
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2; // this one is connected to the external transceiver, we'll use it for sending
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> can3;
CAN_message_t msg1, msg2;
void setup()
{//BEGIN setup()
Serial.begin(115200);
delay(500);
can1.begin();
Serial.println("can 1 begin complete");
can1.setBaudRate(500000);
Serial.println("can 1 baud rate set");
can2.begin();
Serial.println("can 2 begin complete");
can2.setBaudRate(500000);
Serial.println("can 2 baud rate set");
can3.begin();
Serial.println("can 3 begin complete");
can3.setBaudRate(500000);
Serial.println("can 3 baud rate set");
}//END setup()
int rs;
void loop()
{//BEGIN loop()
rs = can1.read(msg2);
Serial.print("CAN1 read status = ");
Serial.println(rs);
if (rs)
{
Serial.print("CAN1 ");
Serial.print("MB: "); Serial.print(msg2.mb);
Serial.print(" ID: 0x"); Serial.print(msg2.id, HEX );
Serial.print(" EXT: "); Serial.print(msg2.flags.extended );
Serial.print(" LEN: "); Serial.print(msg2.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ )
{
Serial.print(msg2.buf); Serial.print(" ");
}
Serial.print(" TS: "); Serial.println(msg2.timestamp);
}
rs = can3.read(msg2);
Serial.print("CAN3 read status = ");
Serial.println(rs);
if ( rs )
{
Serial.print("CAN3 ");
Serial.print("MB: "); Serial.print(msg2.mb);
Serial.print(" ID: 0x"); Serial.print(msg2.id, HEX );
Serial.print(" EXT: "); Serial.print(msg2.flags.extended );
Serial.print(" LEN: "); Serial.print(msg2.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ )
{
Serial.print(msg2.buf); Serial.print(" ");
}
Serial.print(" TS: "); Serial.println(msg2.timestamp);
}
msg1.id = 0x100;
msg1.len = 8;
msg1.buf[0] = 10;
msg1.buf[1] = 20;
msg1.buf[2] = 0;
msg1.buf[3] = 100;
msg1.buf[4] = 128;
msg1.buf[5] = 64;
msg1.buf[6] = 32;
msg1.buf[7] = 16;
rs = can2.write(msg1);
Serial.print("message sent, status = ");
Serial.println(rs);
delay(1000);
}//END loop()
I working on an electronic dash project for my motorhome. The UI is built, and I now need to get it connected to the CANbus. So far I have failed utterly. I assume that it's due to ignorance on my part - something small but critical that I'm missing. Please help before I flush the whole thing...
Here's the setup:
- Teensy 4.0
- Dan Gilbert's (Tall Dog) breakout board with on-board CANbus tansciever
- Separate SN65HVD230 transciever BoB
- All of the above on a breadboard setup wired to send from CAN2 and receive on CAN1 or CAN3. (I'm not sure which bus Daniel's board feeds to, bit I guessed it was one of these.
- Wired thusly:
- BoB GND -> ext Xciever GND
- BoB 3.3v -> ext Xciever 3.3v
- BoB CANL -> ext Xciever CANL
- BoB CANH -> ext Xciever CANH
- BoB pin 0 (CRX2) -> ext Xciever RX
- BoB pin 1 (CTX2) -> ext Xciever TX
- I've tried crossing the Rx and Tx pins with no change in results
- No other wiring, power is coming from the Teensy's micro USB port
I'm using example code I found online (below), and it seems to conform with what I see in the FlexCAN_T4 examples. The output delivered to the serial monitor looks like this:
can 1 begin complete
can 1 baud rate set
can 2 begin complete
can 2 baud rate set
can 3 begin complete
can 3 baud rate set
CAN1 read status = 0
CAN3 read status = 0
message sent, status = 1
CAN1 read status = 0
CAN3 read status = 0
message sent, status = 1
with the last 3 lines repeating infinitely.
Thanks in advance for any help!
Regards,
Randy
//**************************************************************************************************************
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2; // this one is connected to the external transceiver, we'll use it for sending
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> can3;
CAN_message_t msg1, msg2;
void setup()
{//BEGIN setup()
Serial.begin(115200);
delay(500);
can1.begin();
Serial.println("can 1 begin complete");
can1.setBaudRate(500000);
Serial.println("can 1 baud rate set");
can2.begin();
Serial.println("can 2 begin complete");
can2.setBaudRate(500000);
Serial.println("can 2 baud rate set");
can3.begin();
Serial.println("can 3 begin complete");
can3.setBaudRate(500000);
Serial.println("can 3 baud rate set");
}//END setup()
int rs;
void loop()
{//BEGIN loop()
rs = can1.read(msg2);
Serial.print("CAN1 read status = ");
Serial.println(rs);
if (rs)
{
Serial.print("CAN1 ");
Serial.print("MB: "); Serial.print(msg2.mb);
Serial.print(" ID: 0x"); Serial.print(msg2.id, HEX );
Serial.print(" EXT: "); Serial.print(msg2.flags.extended );
Serial.print(" LEN: "); Serial.print(msg2.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ )
{
Serial.print(msg2.buf); Serial.print(" ");
}
Serial.print(" TS: "); Serial.println(msg2.timestamp);
}
rs = can3.read(msg2);
Serial.print("CAN3 read status = ");
Serial.println(rs);
if ( rs )
{
Serial.print("CAN3 ");
Serial.print("MB: "); Serial.print(msg2.mb);
Serial.print(" ID: 0x"); Serial.print(msg2.id, HEX );
Serial.print(" EXT: "); Serial.print(msg2.flags.extended );
Serial.print(" LEN: "); Serial.print(msg2.len);
Serial.print(" DATA: ");
for ( uint8_t i = 0; i < 8; i++ )
{
Serial.print(msg2.buf); Serial.print(" ");
}
Serial.print(" TS: "); Serial.println(msg2.timestamp);
}
msg1.id = 0x100;
msg1.len = 8;
msg1.buf[0] = 10;
msg1.buf[1] = 20;
msg1.buf[2] = 0;
msg1.buf[3] = 100;
msg1.buf[4] = 128;
msg1.buf[5] = 64;
msg1.buf[6] = 32;
msg1.buf[7] = 16;
rs = can2.write(msg1);
Serial.print("message sent, status = ");
Serial.println(rs);
delay(1000);
}//END loop()