stelian
Posts: 3
Joined: Fri Jul 29, 2016 11:42 am

Unable to bring CAN interface up on RPi 3 [solved]

Fri Jul 29, 2016 11:48 am

I followed a few tutorials on how to use CAN on Raspberry and most of them suggested I should add these lines to /boot/config.txt :

Code: Select all

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
I made the CAN controller on breadboard with MCP2515 and I'm pretty sure it is connected properly, including the INT pin from the MCP to GPIO25 on Raspberry.

The schematic is here : http://3.bp.blogspot.com/-6iBPCZobUy4/U ... ematic.png

However, this command always fails :

Code: Select all

ip link set can0 up type can bitrate 500000
saying : cannot find device can0.

I tried adding it manually:

Code: Select all

modprobe can
ip link add can0 type can
but when I try to bring the interface up again, the command hangs and I have to reboot the Pi in order to use it, because most of other unrelated commands hang as well.

Finally, my questions are :

Does the ip link commnad rely on proper can hardware in order to succeed ?
What should I check in order to trace this problem ?

edo1
Posts: 136
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia

Re: Unable to bring CAN interface up on RPi 3

Mon Aug 01, 2016 9:00 pm

With proper wiring and DT overlay can0 should appear automatically.
IMHO your problem is in wiring.

In kernel version 4.8 mcp251x driver will be more talkative, it should help to debug such cases.

stelian
Posts: 3
Joined: Fri Jul 29, 2016 11:42 am

Re: Unable to bring CAN interface up on RPi 3

Mon Aug 08, 2016 1:01 pm

The CAN controller was tested with mbed and Arduino and it works. I also managed to run a SPI loopback test on the Raspberry and it worked. However, I cannot use the controller on the Raspberry Pi. I'm assuming it is a configuration issue or a missing driver. But I have no idea how to trace the cause. Any suggestions ?

Here is my config.txt file. I am using a 16 MHz crystal and the IRQ pin of the MCP2515 is connected to GPIO 25 on the Raspberry.

Code: Select all

# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=48
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=2
#hdmi_mode=14

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# NOOBS Auto-generated Settings:
hdmi_force_hotplug=1

#can config
dtparam=spi=on
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
dtoverlay=spi-dma-overlay


#dtoverlay=pi3-miniuart-bt
#enable_uart=1

device_tree_param=spi=on

jihzed
Posts: 63
Joined: Tue Feb 02, 2016 10:01 am

Re: Unable to bring CAN interface up on RPi 3

Sat Aug 13, 2016 6:28 am

Hello.
I've same problem. I've a Pi 2 B and I install it in february with Raspbian Jessie (21/11/2015). It work correctly.
Unfortunately the micro SD card just dead, and I try to install a new card.

I'm sure the electronic board work correctly because it has work since february with the 1st SD card.
I don't remember any other think that /boot/config.txt to install can bus.

jihzed
Posts: 63
Joined: Tue Feb 02, 2016 10:01 am

Re: Unable to bring CAN interface up on RPi 3

Sat Aug 13, 2016 10:46 am

I try some tests.
I try to update firmware :

Code: Select all

sudo rpi-update
… don't change

I see in /etc/modules

Code: Select all

snd-bcm2835
spi-bcm2835 # or perhaps spi-bcm2708 ; what's the difference ?

# RTC (I don't think this part is bad, the RTC look work correctly)
i2c-dev
i2c-bcm2708
rtc-ds1307
I try to see in /etc/modprobe.d/raspi-blacklist.conf

Code: Select all

#blacklist spi-bcm2708
blacklist i2c-bcm2708
#blacklist mcp251x
don't change, don't work… :(
I'm not a good user of Linux, there is a way to read error message at start (perhaps there is a message, but it's to quick to be read)

jihzed
Posts: 63
Joined: Tue Feb 02, 2016 10:01 am

Re: Unable to bring CAN interface up on RPi 3

Sat Aug 13, 2016 11:14 am

just found.
I don't know if the change of /etc/modules and /etc/modprobe.d/raspi-blacklist.conf are need, but :

in /boot/config/txt:

Code: Select all

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=18000000,interrupt=25
dtoverlay=spi-bcm2835
juste remove "-overlay" since last jessie 08/2016 !!!
ARG ! :shock:

stelian
Posts: 3
Joined: Fri Jul 29, 2016 11:42 am

Re: Unable to bring CAN interface up on RPi 3

Fri Aug 19, 2016 12:05 pm

jihzed wrote:just found.
I don't know if the change of /etc/modules and /etc/modprobe.d/raspi-blacklist.conf are need, but :

in /boot/config/txt:

Code: Select all

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=18000000,interrupt=25
dtoverlay=spi-bcm2835
juste remove "-overlay" since last jessie 08/2016 !!!
ARG ! :shock:
Thank you so much ! It did the trick. In order to get this to work, I flashed a new card with NOOBS. I ran apt-get update and upgrade, then I added the overlays in config.txt without "-overlay", as you suggested, and then the ip link command worked. (after a reboot)
The thing is that on my previous attempts the Pi was running kernel 4.4.15-v7+ (because I upgraded the kernel). On this version I couldn't get the CAN bus to work. But today's NOOBS image comes with kernel 4.4.13-v7+, on which the CAN works fine with your suggestion.

mamuti
Posts: 6
Joined: Fri May 19, 2017 10:21 pm

Re: Unable to bring CAN interface up on RPi 3 [solved]

Sun May 21, 2017 5:06 pm

Hi guys

I hope that you are still checking this post. I have the same problem. I'm trying to initialize PICAN2 on RPi3 model B. Firstly, I was using Kernel 4.9; however, I found that in webpage of "SK Pang electronics" (producer of PICAN2), there is a special note for kernel 4.4 released on May of 2016. So I installed this version (4.4.9-V7+) and tried to edit the config file with/without -overlay; The result was the same! It keeps saying 'cannot find device can0' after entering "sudo /sbin/ip link set can0 up type can bitrate 500000" at PUTTY.
Do you have any suggestions? I'm like a beginner at Linux and also CAN.

Return to “Troubleshooting”