how can I use CAN bus in TX2?

Dear Sandipan,

Thank you so much for your kind support. It is great to learn that SN65HVD230 works fine with TX2 CAN 500kbps communication.
Regarding my test issue. In order to make my question clearly, I list my TX2 setup and test sequence below:

  1. My TX2 setup:
    a. Added MTTCAN as a module, rebuilt kernel
    b. Installed SocketCAN
    c. Connected CAN0 and CAN1 with CAN transceivers as in attached picture:

  2. Load below modules:
    a. $ sudo modprobe can
    b. $ sudo modprobe can_raw
    c. $ sudo modprobe can_dev
    d. $ sudo modprobe mttcan

  3. Configure CAN0 and CAN1:
    a. $ sudo ip link set can0 type can bitrate 500000
    b. $ sudo ip link set up can0
    c. $ sudo ip link set can1 type can bitrate 500000
    d. $ sudo ip link set up can1

  4. Check CAN0 and CAN1 with “ip –details link show can*”, both are in ERROR-WARNING state.

  5. Open a terminal and set CAN1 to “$ candump can1”

  6. Open another terminal, and set CAN0 to send data using “$ cansend can0 123#112233” or “cangen can0”

  7. Check terminal which set “$candump can1” previously, it doesn’t show any signal.

  8. Check CAN0 and CAN1 with “ip –details link show can*” again, CAN0 went to BUS-OFF state and CAN1 went to ERROR-PASSIVE state.

Do you see any issues with my tests? Could you give me some hints?

Thank you so much for your help in advance!

Best regards,
Abby

It looks like a loose connection with the Transceivers.
May be you can check the soldering part where the Transceivers are connected.

It is unlikely since I checked the connection multiple times. However, I will double check again and come back to you. In the meantime, please share if you come with any other ideas.

Thanks a lot,
Abby

Abby,

With the same setup, I can see proper communication between two CAN nodes.
And interface statics displays as ERROR-ACTIVE state.

I still suggest to check the connection to be exactly as the diagram that you have attached.
Also double check the soldering regions if you have any.

Below descriptions are for your reference:

Port : J26
Pin No Details
1 ===== CAN wake

3 ===== CAN0 STAND BY
5 ===== CAN0 RX
7 ===== CAN0 TX
9 ===== CAN0 ERR

13 ==== CAN1 STANDBY
15 ==== CAN1 RX
17 ==== CAN1 TX
19 ==== CAN1 ERR

Let us know if you still have issue.

Thanks & Regards,
Sandipan

hi spatra do i need to use the pin #1 to wake the CAN up? I Mean do i need to connect anything to J26 #1? to use the CAN bus?

Hi Gyhyong,

Presently CAN controller on TX2 works without using CAN wake pin.

Hi Sandipan,

I double checked my connection and soldering. The tests still failed.

I wonder what exact CAN transceiver do you use? I use CJMCU-230 with SN65HVD230 (marked as VP230 61M CTCVG4) on its package. It is configured to slope control mode with a 10k resistor. Have you done any changes to your CAN transceiver to make the CAN communication working?

What is length of your CAN bus? Do you need to add any termination resistor to your can bus?

I look forward to hearing from you soon. Thank you so much.

Abby

Abby,

I am also using CJMCU-230 with SN65HVD230.
Have a look at attached image for same.

I faced similar issue while connecting transceiver on breadboard using the connector which was supplied along with the transceiver.
We found it working fine after properly soldering and placing on the breadboard.

And you don’t have to configure with 10K resistor/termination resistor as that is there as part of the SoC - CJMCU-230.

Please check with the attachment and let us know if are you using it same way.

Also check the CAN Bus status when in ideal state (before transmitting/receiving the packets).

Thanks & Regards,
Sandipan

Dear Sandipan,

Thank you so much for your messages.

I finally figured out the route cause in my test setup. It turns out that there are some issues in the CAN transceivers that I used (CJMCU-230 PCBs). One obvious issue is that the CJMCU-230 PCBs have wrong resistor values of both resistors on it. After replacing them with same products from a different vendor supply, the tests passed.

I apologize for the inconvenience that I may caused and would like to thank you again for all your kind support.

Best regards,
Abby

Thank you for everyone who shared their ideas.
I just got the can data from the car
I have several more things to do.

  1. Is there any automatic way to do the ip link on boot up? So I can do “candump can0” right after boot up
  2. Is there any way to get the can data from python code?

Thank you

Hi Abby,

Great that your setup works fine now.
Thank you for keeping us updated with your result.

You can also mark accept to any answer which was helpful, so it may help others as well.

Thanks & Regards,
Sandipan

Hi Gyuhyong,

To answer your queries:

Is there any automatic way to do the ip link on boot up? So I can do “candump can0” right after boot up
Ans: Yes it can be automated during boot up sequence.
You can check the feasibility to add the same code snippet to any of the init scripts
or
you can also add it to the bash script - ~/.bashrc (particular user can avail it)

Is there any way to get the can data from python code?
Yes it is possible to code in python for this.
Right now I don’t understand python.
I wish someone will get in touch regarding the python code snippet to do this work.

Thanks & Regards,
Sandipan

Hi all,

I’ve followed Spatra’s post and rebuilt the kernel and ran all of the set-up commands from the post.

I do see can0 and can1 with ifconfig -a but I don’t see anything on either port with candump can0 when I run cansend can0 123#abcdabcd

Should I be expecting the same thing as when I try the same thing over vcan0, running cansend or cangen over that interface and seeing the messages over candump?

Here are the statuses of each CAN interface:

nvidia@tegra-ubuntu:~/ssd_caffe$ ip -details -statistics link show can0
4: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 72 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can <BERR-REPORTING,FD> state BUS-OFF (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 500000 sample-point 0.875 
	  tq 25 prop-seg 34 phase-seg1 35 phase-seg2 10 sjw 1
	  mttcan: tseg1 2..255 tseg2 0..127 sjw 1..127 brp 1..511 brp-inc 1
	  dbitrate 2000000 dsample-point 0.750 
	  dtq 25 dprop-seg 7 dphase-seg1 7 dphase-seg2 5 dsjw 1
	  mttcan: dtseg1 1..31 dtseg2 0..15 dsjw 1..15 dbrp 1..15 dbrp-inc 1
	  clock 40000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          2          0          1          1          0         
    RX: bytes  packets  errors  dropped overrun mcast   
    40         5        2       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0

nvidia@tegra-ubuntu:~/ssd_caffe$ ip -details -statistics link show can1
5: can1: <NO-CARRIER,NOARP,UP,ECHO> mtu 72 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can <BERR-REPORTING,FD> state BUS-OFF (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 500000 sample-point 0.875 
	  tq 25 prop-seg 34 phase-seg1 35 phase-seg2 10 sjw 1
	  mttcan: tseg1 2..255 tseg2 0..127 sjw 1..127 brp 1..511 brp-inc 1
	  dbitrate 2000000 dsample-point 0.750 
	  dtq 25 dprop-seg 7 dphase-seg1 7 dphase-seg2 5 dsjw 1
	  mttcan: dtseg1 1..31 dtseg2 0..15 dsjw 1..15 dbrp 1..15 dbrp-inc 1
	  clock 40000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          2          0          1          1          0         
    RX: bytes  packets  errors  dropped overrun mcast   
    40         5        2       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0

I see that the state is at BUS-OFF instead of ERROR-WARNING
 Did I miss something in my setup?
Or does this only work when I have the transceiver set up first? Even if I am only checking the same interface where I did cansend to?

UPDATE
Finally got it working by playing around with the TX2 and rebooting the system, CAN0/1 finally went to the ERROR-WARNING state instead of BUS-OFF. Once I hooked it up with CAN transceivers and tested on both 500K and 250K network, I was able to read the outputs with candump, and the state became ERROR-ACTIVE. My cansend messages also showed up once that happened. So it does require some CAN activities for it to switch to the proper state.

Hi,

Thank you for the update and great that it started working.

Do note that you can also do various activities with respect to CAN packets (i.e. receiving only on interested packet types, generating special CAN packets etc) on the network using cangen utility.

Thank you.

The right way to do this on Linux with systemd is to generate “unit” files that bring up the interfaces, and then make your boot target depend on those units (services.) That way, you can get automatic restart if there are services you depend on, logging for the specific interface is inspectable with journalctl, and so forth.

Another way that can work as well is to add the interfaces, and their settings, to the /etc/network/interfaces file or a file in the /etc/network/interfaces.d directory. This still lets the networking subsystem know about the interfaces earlier in the boot than if you ran a “script” to do so.

Putting the functions in a .bashrc file may be convenient very early in development, but is generally a really bad idea for any kind of system you’re trying to actually build a “real” embedded image for.

Hi ShaneCCC, can you confirm that this has been enabled by default in kernel in the Jetpack L4T 28.1 release?

Thanks,

If the can transceiver is not correctly connected or is incompatible, will there still be activity on the TX line when using a command like “cansend can0 xxx#xxxxxxxx”?

I believe the corrent behavior when seeing bad CAN transcievers is to turn off the interface, to isolate the device from a possibly broken bus. So, no, I might not expect to see pins “wiggle” if the transciever is incorrectly connected.

Is it possible to run at 1M?

Hi everyone.

I have some questions in TX2.

I run according to your opinion.
I try to install SocketCAN and modify tegra18_defconfig.
Also, I command
sudo modprobe can
sudo modprobe mttcan
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0

I can see CAN communication when I type “ifconfig”

I connect hardware

        TX2         -       TJA1050  

Rx : J26 - 5 4
Tx : J26 - 7 1
Vcc: J26 - 8 3
GND: J26 - 11 2

I command
cangen can0 -g 4 -I 42A -L 2 -D i -v -v

I see terminal on monitor, but CAN transiver isn’t work.
can0 42A [2] 00 00

How can I solve the problem