mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post Reply
jinhyeongin
Posts: 17
Joined: Fri Jul 23, 2021 4:14 pm
languages_spoken: english
ODROIDs: n2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by jinhyeongin »

I want to use the MCP2515 Can module. I refer to the link below.
https://wiki.odroid.com/common/applicat ... io/can-bus

I'll try to test CAN-bus link between 2 ODROID-N2/C4 boards. One Odroid is said to have been successfully initialized by mcp2515. However, the other one says that mcp2515 cannot be initialized.

I did it by following the link above.
->
root@odroid:~# apt update && apt full-upgrade

root@odroid:/etc# vim /media/boot/config.ini

; Device Tree Overlay
overlay_resize=16384
overlay_profile=
overlays="spi0 i2c0 i2c1 uart0 can0"

Added "can0" to Overlay and rebooted the system.



<Odroid that failed to initialize mcp2515>

root@odroid:/# dmesg | grep spi
[5.503569] meson-spicc ffd13000.spi: registered master spi0
[ 5.504150] spi spi0.1: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[5.504388] meson-spicc ffd13000.spi: registered child spi0.1
[ 5.504434] spi spi0.0: setup mode 0, 8 bits/w, 100000000 Hz max --> 0
[5.504575] meson-spicc ffd13000.spi: registered child spi0.0
[ 9.773967] mcp251x spi0.1: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 9.796598] mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?
[ 9.797501] mcp251x spi0.1: Probe failed, err=19
root@odroid:/# lsmod | grep spi
spidev 20480 0
spi_meson_spicc 20480 0
root@odroid:/# lsmod | grep mcp251x
mcp251x 24576 0
can_dev 24576 1 mcp251x


root@odroid:/# ls /sys/class/net/
eth0 lo wlan0

root@odroid:~# ifconfig can0
can0: error fetching interface information: Device not found

root@odroid:~# ls /sys/bus/spi/drivers/mcp251x/
bind module uevent unbind


<Odroid that successfully initialized mcp2515>
root@odroid:/# lsmod | grep spi
spidev 20480 0
spi_meson_spicc 20480 0
root@odroid:/# lsmod | grep spi
spidev 20480 0
spi_meson_spicc 20480 0
root@odroid:/# dmesg | grep spi
[ 5.522359] meson-spicc ffd13000.spi: registered master spi0
[ 5.522524] spi spi0.1: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[5.522629] meson-spicc ffd13000.spi: registered child spi0.1
[ 5.522643] spi spi0.0: setup mode 0, 8 bits/w, 100000000 Hz max --> 0
[ 5.522798] meson-spicc ffd13000.spi: registered child spi0.0
[ 10.407753] mcp251x spi0.1: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 10.431153] mcp251x spi0.1 can0: MCP2515 successfully initialized.

root@odroid:/# lsmod | grep spi
spidev 20480 0
spi_meson_spicc 20480 0

root@odroid:/# lsmod | grep mcp251x
mcp251x 24576 0
can_dev 24576 1 mcp251x

root@odroid:/# ls /sys/class/net/
can0 eth0 lo

root@odroid:/# ifconfig can0
can0: flags=128<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

root@odroid:/# ls /sys/bus/spi/drivers/mcp251x/
bind module spi0.1 uevent unbind


Out of the 2 Odroids I have, 1 succeeded in initializing mcp2515, and 1 said it could not initialize, but both updated the kernel and added "can0" to the overlay. I don't know why one works and one doesn't.

Please help me what to do when MCP2515 won't initialize.

User avatar
odroid
Site Admin
Posts: 38030
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1997 times
Been thanked: 1205 times
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by odroid »

If can_dev and mcp251x modules exist in the lsmod output, software configuration should be fine.
Try measuring SPI signals and power rails with an oscilloscope to check if your wiring is wrong or not.

jinhyeongin
Posts: 17
Joined: Fri Jul 23, 2021 4:14 pm
languages_spoken: english
ODROIDs: n2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by jinhyeongin »

To solve this problem, I did a fresh install of ubuntu img and followed the link "https://wiki.odroid.com/odroid-n2/appli ... io/can-bus" and the problem was solved.

mcp2515 was successfully initialized on both odroid boards I currently have, and it was successfully performed according to the link "https://wiki.odroid.com/odroid-n2/appli ... io/can-bus".


https://blog.naver.com/PostView.naver?b ... ength=6994

I connected it like this.
These users thanked the author jinhyeongin for the post:
odroid (Wed Sep 01, 2021 2:57 pm)

jinhyeongin
Posts: 17
Joined: Fri Jul 23, 2021 4:14 pm
languages_spoken: english
ODROIDs: n2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by jinhyeongin »

I used an oscilloscope to observe the output waveform of the transmitting part.
https://blog.naver.com/jhi5269/222491535229

And as a result of observing ifconfig can0 on board 1 after sending from board 2, the number of RX/TX packets did not change.

root@odroid:~# candump can0
^Z
[2]+ Stopped candump can0
root@odroid:~# ifconfig can0
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 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


Then, each board was subjected to a loopback test.

As a result of the loopback test for board 1, the ifconfig can0 result did not change, and for board 2, the number of transmission packets was changed.

<1st board result>
root@odroid:~# ifconfig can0
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 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

<2st board result>
can0: flags=129<UP,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 0 (0.0 B)
RX errors 2 dropped 0 overruns 0 frame 2
TX packets 5 bytes 15 (15.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

As a result of the loopback test, it seems that there is something wrong with the can module connected to the first board.

jinhyeongin
Posts: 17
Joined: Fri Jul 23, 2021 4:14 pm
languages_spoken: english
ODROIDs: n2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by jinhyeongin »

I tried to use board 1 to receive and board 2 to transmit.
When the order is accidentally changed and board 1 is used as transmit and board 2 as receive,
first dat is received on board 2 and the next data is not received.

The current situation is as follows.
1. When board 1 is set to receive and board 2 is set to transmit, communication is not possible.
2. When board 1 is transmitted and board 2 is received, communication is only performed once for the first time.
3. ifconfig can0 down
ifconfig can0 up
Even if you test again after executing , communication is possible only the first time, and then communication is not possible.

Once communication is established, I think it is not a connection problem. I think that communication is only done once for the first time as a problem. Please help me what to do in this case.




<No. 1 board output>
root@odroid:~# ip link set can0 type can bitrate 125000 triple-sampling on
root@odroid:~# ifconfig can0 up
root@odroid:~# candump can0
^Z
[1]+ Stopped candump can0
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# candump can0
^Z
[2]+ Stopped candump can0
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# ifconfig can0 down
root@odroid:~# ifconfig can0 up
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33


<No.2 board output>
root@odroid:~# ip link set can0 type can bitrate 125000 triple-sampling on
root@odroid:~# ifconfig can0 up
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# candump can0
can0 500 [3] 11 22 33
^Z
[1]+ Stopped candump can0
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# cansend can0 500#11.22.33
root@odroid:~# candump can0
^Z
[2]+ Stopped candump can0
root@odroid:~# ifconfig can0 down
root@odroid:~# ifconfig can0 up
root@odroid:~# candump can0
can0 500 [3] 11 22 33

User avatar
odroid
Site Admin
Posts: 38030
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1997 times
Been thanked: 1205 times
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by odroid »

I have no idea since we had no such issue when we tested.
Was there any strange kernel message from "dmesg" output?
Do you have other MCP2515 modules to narrow down root causes?

brad
Posts: 1449
Joined: Tue Mar 29, 2016 1:22 pm
languages_spoken: english
ODROIDs: C2 C4 HC4 N1 N2 N2+ H2 H2+ (64 bit ftw)
Location: Australia
Has thanked: 135 times
Been thanked: 222 times
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by brad »

I might be on the wrong track here but I notice you are stopping the candump with CTRL-Z. (effectively freezing the process in the background)

Maybe this is causing your issue as the can interface will be opened by your frozen process possibly freezing it as well.

Instead of CTRL-Z after running candump just start it in the background to see if it resolves the problem (use the & after the command).

Code: Select all

root@odroid:~# candump can0 &
Reboot first or ensure you have no existing stopped background jobs by using the "jobs" command.

jinhyeongin
Posts: 17
Joined: Fri Jul 23, 2021 4:14 pm
languages_spoken: english
ODROIDs: n2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?

Post by jinhyeongin »

Currently, the dmesg output for both board 1 and board 2 is as follows.
I didn't see any strange kernel messages.

root@odroid:~# dmesg | grep spi
[ 5.546461] meson-spicc ffd13000.spi: registered master spi0
[ 5.546922] spi spi0.1: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[5.547014] meson-spicc ffd13000.spi: registered child spi0.1
[ 5.547026] spi spi0.0: setup mode 0, 8 bits/w, 100000000 Hz max --> 0
[5.547081] meson-spicc ffd13000.spi: registered child spi0.0
[ 11.150995] mcp251x spi0.1: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 11.178132] mcp251x spi0.1 can0: MCP2515 successfully initialized.
root@odroid:~# lsmod | grep mcp251x
mcp251x 24576 0
can_dev 24576 1 mcp251x

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 1 guest