1

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 :

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/UFB4djlVbwI/AAAAAAAAAj8/Fem4E_5u_bw/s1600/Design1+-+ARM+-+minimal+-+Schematic.png

However, this command always fails :

ip link set can0 up type can bitrate 500000

saying : cannot find device can0.

I tried adding it manually:

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 :

  1. Does the ip link commnad rely on proper can hardware in order to succeed ?

  2. What should I check in order to trace this problem ?

  • UPDATE : The controller was tested with mbed and Arduino and it works fine. I'm assuming it is a configuration issue or a missing driver. I have no idea how to trace the problem. Any suggestions ? – Stelian Saracut Aug 8 '16 at 13:04
7

UPDATE : It works now. There were several problems. At first, I thought the problem was caused by the kernel update, so I made a fresh SD card with kernel 4.4.13-v7+. Then someone on the Raspberry Pi forum pointed out that the overlays should be written without '-overlay' at the end (in /boot/config.txt).

I added this to the /boot/config.txt and now I have two CAN interfaces.

#CAN bus controllers
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=24

dtoverlay=spi-bcm2835

Then I could enable them manually with :

ip link set up can0 type can bitrate 500000

Then I made them start at boot by writing this in /etc/network/interfaces

auto can0
iface can0 inet manual
   pre-up /sbin/ip link set can0 type can bitrate 500000 triple-sampling on
   up /sbin/ifconfig can0 up
   down /sbin/ifconfig can0 down

auto can1
iface can1 inet manual
    pre-up /sbin/ip link set can1 type can bitrate 500000 triple-sampling on
    up /sbin/ifconfig can1 up
    down /sbin/ifconfig can1 down

Final result shown by ifconfig :

can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
      UP RUNNING NOARP  MTU:16  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:10 
      RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

can1      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
      UP RUNNING NOARP  MTU:16  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:10 
      RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.