Hi Everyone,
I had a sketch that is sniffing for CAN devices (I have a brushless motor controller over CAN) and it didn't work.
Components:
- Teensy 4.1
- Sn65Hvd230 Bus Transceiver
So I tried to do a loopback test and that didn't work either.
My loopback is just connecting CANH and CANL - I only saw one other post testing this board but it used 2 transceivers.
ChatGPT tells me a loopback with 1 transceiver should work. Is that wrong?
And is the easiest way to test if CAN is working, by using 2 of these modules?
Here is a diagram
And here is the code.
On the serial monitor it shows the message sending but nothing recieved,
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
CAN_message_t msgTx, msgRx;
elapsedMillis sendTimer;
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("FlexCAN_T4 minimal test");
Can1.begin();
Can1.setBaudRate(500000); // Match transceiver speed
msgTx.id = 0x123;
msgTx.len = 8;
for (int i = 0; i < 8; i++) {
msgTx.buf[i] = i + 1;
}
}
void loop() {
if (sendTimer > 1000) {
Serial.println("Sending CAN message...");
Can1.write(msgTx);
sendTimer = 0;
}
if (Can1.read(msgRx)) {
Serial.print("Received ID: 0x");
Serial.println(msgRx.id, HEX);
Serial.print("Data: ");
for (int i = 0; i < msgRx.len; i++) {
Serial.print(msgRx.buf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}
Yes I tried swapping RX and TX too.
If this is impossible I'll try with 2 transceivers. Thanks for any replies!
Thanks