how can I use CAN bus in TX2?

thankyou everyone’suggest. i operate your suggest.
in the terminal , i execute the command 'dmesg
', report an error
“[ 99.095649] can :version magic '4.4.15-tegra SMP preempt mod_unload aarch64’should be ‘4.4.15 SMP preempt mod_unload aarch64’”
should i resolve this question??
and i execute the command ‘ifconfig -a’
, i cannot see any information about ‘can’.
in addition , i execute the command
sudo modprobe can
, prompt error
modprobe:ERROR:could not insert ‘can’:Exec format error

and the command
‘sudo modprobe mttcan’
,
prompt error
modprobe: FATAL:module mttcan not found in directory /lib/modules/4.4.15

should i resolve this question??

thankyou ZP ! it’s useful!

It looks like your kernel and your module were configured with slightly different kernel versions.
They need to match for the kernel to be happy.

Yes,need to modify the Makefile, add
EXTRAVERSION = -tegra

then the kernel verson will be same as the NV’s.

Could some one write up a slightly more detailed version of how to rebuild the kernel with can enabled?

I tried many times, in the end I was never successful. I tried with GitHub - jetsonhacks/buildJetsonTX2Kernel: Build the NVIDIA Jetson TX2 Kernel on the device itself, with no success. Also my tegra18_defconfig doesn’t contain the CONFIG_MTTCAN flag, while there are CONFIG_CAN, CONFIG_SLCAN flags. I tried adding the MTTCAN flag with no success.

Thanks for the help!

These are the steps can be followed to enable and check CAN on TX2.

  1. Enable kernel support for mttcan(Other required modules are already supported)
    CONFIG_MTTCAN = m (Here mttcan is compiled as a module)

  2. Insert CAN BUS subsystem support module.
    modprobe can

  3. Insert Raw CAN protocol module (CAN-ID filtering)
    modprobe can_raw

  4. Real CAN interface support (for our case, it is: mttcan)
    modprobe mttcan (dependent module is can_dev: can driver with netlink support)

  5. CAN interface settings for both the controllers
    ip link set can0 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
    ip link set up can0
    ip link set can1 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
    ip link set up can1

    CAN interfaces are up now. Use ifconfig to list all the interfaces which are up.

  6. Installation of user app to check CAN communication
    sudo apt-get install can-utils

  7. Commands to run to check CAN packet send/receive
    broadcasting a can data packet:
    cansend <can_interface> <can_frame>
    e.g. cansend can0 123#abcdabcd

    Receiving a can data packet:
    candump can_interface
    e.g. candump can1

    Different tools (i.e. cangen, cangw etc) can be used for various filtering options.

  8. To check the interface statistics
    ip -details -statistics link show can0
    ip -details -statistics link show can1

Thanks & Regards,
Sandipan

Hi Spatra,

Thank you so much for the nice instructions. I followed it step by step, however I can not get your CAN test result. May i ask few questions?

  • Did you connect any CAN transceivers in your test setup? Is SN65HVD230 a working choice?
  • When I setup both CANs as you did, both CANs go to ERROR-WARNING state. After I send a message from can0, can0 goes to BUS-OFF state and can1 goes to ERROR-PASSIVE state. Do you know what is wrong?

I look forward to hearing from you soon. Thanks in advance.

-Abby

Does anyone tried CAN transceiver SN65HVD230 with TX2 and succeed with speed 500kbps?

Thanks a lot,
Abby

Hi Abby,

Thank you for the question.

Please note that, CAN node consists of a CAN controller and a CAN transceiver.
Hence, you’ll need to have a CAN transceiver with TX2 to make the setup behave as a proper CAN node/network.
Without the Transceiver, only BUS functionality can be used but not as CAN network communication.

Regarding Transceiver: Yes, SN65HVD230 is a good option to choose as a CAN transceiver with TX2. Its verified.

Also do note that for easy setup and testing basic feature you can use cansend and candump utilities.
Cangen can also be used for more detailed usage like packet filtering and CAN packet generation etc.
These commands can be found under can-utils package.

To your Second comment:
Yes, we are using 500 kbps speed and it works fine.
If are you getting any error at this speed, please share the error logs.

Hope this helps!

Thanks & Regards,
Sandipan

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