Using MCP2515(SPI-to-CAN) on Xavier LOOP test works fine but can't comnicate with other CAN device

Dear NV_Team,

We use SPI bus and MCP2515 to extand a new can bus, and can0 loop test is fine, but it can’t conmunicate with other can devices. Can you give some advice about how to debug it?

  1. SPI1(J57/A56/D55/E55) works fine (loop test spi and spi driver of mcp2515 works fine).
  2. MCP2515 can controller( with SN65HVD231DG4 as tranciever) loop test is fine.
  3. MCP2515(with SN65HVD231DG4 as tranciever) comunicate with Xavier SOM can controller(SN65HVD231DG4 tranciever) both failed, CAN_H/L hardware connection is fine.
  4. MCP2515 Xavier driver code using L4T source code.
dmesg log about spi and mcp2515:
mcp251x spi0.0 can0: MCP2515 successfully initialized.
can: controller area network core (rev 20120528 abi 9)
can: raw protocol (rev 20120528)

nvidia@xavier:~$ ifconfig 
can0: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 9  bytes 32 (32.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 32 (32.0 B)
        TX errors 1  dropped 1 overruns 0  carrier 1  collisions 0

can1: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 2  bytes 16 (16.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 4 overruns 0  carrier 4  collisions 0
        device interrupt 68  

can2: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 69  
CAN0 Loop test
nvidia@xavier:~$ sudo ip link set can0 type can bitrate 1000000 loopback on
nvidia@xavier:~$ sudo ip link set up can0
nvidia@xavier:~$ candump can0 &
nvidia@xavier:~$ cansend can0 123#abcdabcd
nvidia@xavier:~$
  can0  123   [4]  AB CD AB CD
  can0  123   [4]  AB CD AB CD

nvidia@xavier:~$ cansend can0 123#abcdabcd
nvidia@xavier:~$ 
  can0  123   [4]  AB CD AB CD
  can0  123   [4]  AB CD AB CD
CAN0 connect to Xavier CAN1(MTTCAN), transmit to each other and no data received (both side)
nvidia@xavier:~$ sudo ip link set can0 type can bitrate 80000
nvidia@xavier:~$ sudo ip link set up can0
nvidia@xavier:~$ sudo ip link set can1 type can bitrate 80000
nvidia@xavier:~$ sudo ip link set up can1
nvidia@xavier:~$ cansend can1 123#abcdabcd

Another terminal to receive can data (can0 is mcp2515, can1 is xaviver can controller)
nvidia@xavier:~$ candump can0
  can0  0AE9CB27   [0]  remote request

But CAN0 send and CAN1 receive no date.
nvidia@xavier:~$ cansend can0 123#abcdabcd

Another terminal to receive can data (can0 is mcp2515, can1 is xaviver can controller)
nvidia@xavier:~$ candump can1  #no data


Dear NV_Team,

SPI and MCP2515 dtsi configuration :

tegra194-p2888-0001-p2822-0000-common.dtsi

	can_clock: can_clock {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <20000000>;
		clock-accuracy = <100>;
	};
	
	spi@3210000 {
		status = "okay";
		spi@0 {		
			compatible = "microchip,mcp2515";
			reg = <0x0>;
			clocks = <&can_clock>;
			spi-max-frequency = <10000000>;
			interrupt-parent = <&tegra_main_gpio>;
			interrupts = <TEGRA194_MAIN_GPIO(M, 1) 0x1>;
			controller-data {
				nvidia,enable-hw-based-cs;
				nvidia,cs-setup-clk-count = <0x1e>;
				nvidia,cs-hold-clk-count = <0x1e>;
				nvidia,rx-clk-tap-delay = <0x1f>;
				nvidia,tx-clk-tap-delay = <0x0>;
			};
		};
		spi@1 {
			compatible = "spidev";
			reg = <0x1>;
			spi-max-frequency = <33000000>;
			controller-data {
				nvidia,enable-hw-based-cs;
				nvidia,rx-clk-tap-delay = <0x11>;
			};
		};
	};

Hi NV_Team,

Can you give me some advice?

Thanks.

Hi All,

I have verified different MCP2515 modules, all of them can’t communicate with Jetson MTTCAN, but they can communicate with each other(MCP2515).
I have changed to MCP2518FD module, and it works on Jetson Xaveir/NX/Nano. It can communicate with Jetson MTTCAN.

Hi, Luna2020, I have two question,

1.did you need execute sudo /opt/nvidia/jetson-io/jetson-io.py, enable the spi1/3? If I do not execute this command, I cannot initialize MCP2515 properly.

2.Have you tried to communicate using other baud rates, such as 500000/1000000?I can communicate with a baudrate of 125000, but not if it exceeds it

Hi noSIM,

  1. Xavier default dtsi disable spi1/3, so you need to enable spi1/3 first, then you can using spi to communicate with other devices.

  2. The max can clock for mcp2515 in my Xavier Devkit is 200k, if setting higher than 200k dmesg shows ‘bitrate error 1.2%’ and get error for tranceive.

Commands:

sudo devmem2 0x0243d010 w 0x00000400
sudo devmem2 0x0243d020 w 0x00000450
sudo devmem2 0x0243d040 w 0x00000400
sudo devmem2 0x0243d050 w 0x00000400
sudo devmem2 0x0243d058 w 0x00000400
echo 'nvidia' | sudo -S sudo modprobe can
echo 'nvidia' | sudo -S sudo modprobe can_raw
echo 'nvidia' | sudo -S sudo modprobe can_dev

sudo insmod /lib/modules/4.9.140-tegra/kernel/drivers/net/can/spi/mcp251x.ko
echo 'nvidia' | sudo -S sudo ip link set can0 type can bitrate 200000
echo 'nvidia' | sudo -S sudo ip link set up can0
echo 'nvidia' | sudo -S sudo ip link set can1 type can bitrate 200000
echo 'nvidia' | sudo -S sudo ip link set up can1
dmesg | tail -n 10

candump can0 &
cangen can1

I tried what you mentioned, it is indeed.
The baud rate can only reach 250,000, and an error will be reported ‘bitrate error 1.2%’ if it exceeds it; do you know what to do if want to increase it, I need to reach 1,000,000 bitrate