I've made a PCB with a CAN transceiver and two RJ11 ports. The following image shows the schematics. The CAN transceiver is the TCAN330GD.
I use CAN0 on the Teensy 3.6, i.e. port 3 for TX and port 4 for RX. As you can see, TXD from the transceiver is connected to TX on the Teensy, and RXD on the transceiver is connected to RX on the Teensy. I checked for continuity with a multimeter and the pins are indeed connected according to the schematics. This brings me to my first question;
Is this the correct way to connect it?
I've found a lot of conflicting information out there. I've found multiple forum posts that say the way I've connected it now is the correct way. However, pawelsky's FlexCAN library , which I'm using, says to connect it the other way around; i.e. TX to RXD, RX to TXD. This had me very unsure. Since my original design have the pins connected TX to TXD, RX to RXD, I tried that first without any luck. Then I broke the PCB tracks and connected TX to RXD and RX to TXD with two jumper cables. Still no luck.
My testing setup is using a node (another microcontroller) which continuously sends out CAN data. I know this sends correctly because I've connected it to a CAN viewer which prints all received data to serial. However, when I connect the teensy to my sending node, the teensy doesn't receive any data. I also connected the teensy to the CAN viewer and tried to send, but no messages were received. The CAN network is terminated correctly with 120 Ohm resistor in each end.
The code I used to read CAN data is as follows:
This code prints correctly to serial if I manually set the data in the msg object. However, the msg object is not updated by `canbus.read(msg)`. If I just print `canbus.available()` to serial, there's just zeros, i.e. no available messages.
---
Any help in this matter would be greatly apprechiated. I've struggled with this issure for far too long now and I'm completely out of ideas of what I can try. Please don't hesitate to ask if there's any information I can provide which can help you to answer this question.
I use CAN0 on the Teensy 3.6, i.e. port 3 for TX and port 4 for RX. As you can see, TXD from the transceiver is connected to TX on the Teensy, and RXD on the transceiver is connected to RX on the Teensy. I checked for continuity with a multimeter and the pins are indeed connected according to the schematics. This brings me to my first question;
Is this the correct way to connect it?
I've found a lot of conflicting information out there. I've found multiple forum posts that say the way I've connected it now is the correct way. However, pawelsky's FlexCAN library , which I'm using, says to connect it the other way around; i.e. TX to RXD, RX to TXD. This had me very unsure. Since my original design have the pins connected TX to TXD, RX to RXD, I tried that first without any luck. Then I broke the PCB tracks and connected TX to RXD and RX to TXD with two jumper cables. Still no luck.
My testing setup is using a node (another microcontroller) which continuously sends out CAN data. I know this sends correctly because I've connected it to a CAN viewer which prints all received data to serial. However, when I connect the teensy to my sending node, the teensy doesn't receive any data. I also connected the teensy to the CAN viewer and tried to send, but no messages were received. The CAN network is terminated correctly with 120 Ohm resistor in each end.
The code I used to read CAN data is as follows:
Code:
CAN_message_t msg;
canbus.read(msg);
char str[32] = "[";
char tmp[32] = "";
itoa(msg.id, tmp, 16);
strcat(str, tmp);
strcat(str, ":");
itoa(msg.len, tmp, 10);
strcat(str, tmp);
strcat(str, ":");
for (int i = 0; i < 8 - msg.len; i++) { // adds padding zeros so str len is constant
const char * tmp2 = "00";
strcat(str, tmp2);
strcat(str, "-");
}
for (int i = 0; i < msg.len; i++) {
itoa(msg.buf[i], tmp, 16);
if (msg.buf[i] <= 0xf) {
char tmp2[2] = "0";
strcat(tmp2, tmp);
strcat(str, tmp2);
}
else {
strcat(str, tmp);
}
if (i < msg.len - 1) {
strcat(str, "-");
}
}
strcat(str, "]");
Serial.println(str);
This code prints correctly to serial if I manually set the data in the msg object. However, the msg object is not updated by `canbus.read(msg)`. If I just print `canbus.available()` to serial, there's just zeros, i.e. no available messages.
---
Any help in this matter would be greatly apprechiated. I've struggled with this issure for far too long now and I'm completely out of ideas of what I can try. Please don't hesitate to ask if there's any information I can provide which can help you to answer this question.