This blog shows the steps required to install the software on the Raspberry 2 Model for use with PiCAN board
All the previous kernel modules will not work with the current Raspbian (2015-02-16) for the Raspberry Pi 2. However the next version of the kernel will have the mcp251x driver compiled in. We can upgrade the firmware now with the new driver. These instruction will also work on the Raspberry B+.
Start by installing a brand new version of Raspbian (2015-02-16) kernel 3.18
Enable the SPI interface by running raspi-config.
cd /usr/bin
sudo ./raspi-config
Select Advanced Options.
Select A6 SPI
Confirm you want the SPI interface enabled. Confirm you want the SPI kernel module to be loaded by default, then exit.
Do an update first.
sudo apt-get update
sudo apt-get upgrade
sudo reboot
Add the overlays by:
sudo nano /boot/config.txt
Add these 3 lines to the end of file:
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
Reboot Pi:
sudo reboot
You can now bring the CAN interface up:
sudo /sbin/ip link set can0 up type can bitrate 500000
Download and copy the CAN test programs to the Pi.
To send a CAN message use :
./cansend can0 7DF#0201050000000000
This will send a CAN ID of 7DF. Data 02 01 05 – coolant temperature request.
Installing can-tools.
To write your own CAN-Bus program follow this blog.
_
Hello,
I’m trying to install PICAN on RPi 2, but I don’t know how and where to install “CAN test” programs. I have this archiv downloaded unpacked on PC and uploaded through WinSCP to RPi /home/pi/can_test but I could not see how to continue with instalation. Sorry maybe for stupid questions, but I am on basic level with RPi.
Thanks for help.
In the can_test directory are the test programs. Just change into that directory and run the test programs like this
./cansend can0 7DF#0201050000000000
Yes that I tried, but without sudo systems return:
-bash: ./cansend: Permission denied
If I tried with sudo system return:
sudo: ./cansend: command not found
Any idea?
I made all steps as are above.
Have you changed into the can_test directory? Do a “ls” and see if cansend is there or not.
Yes I am in can_test folder and all filles I can see are:
canbusload, candump, cangen, canlogserver, cansend, libsocketcan.la, can-calc-bit-timing, canfdtest, cangw, canplayer, cansniffer, libsocketcan.so.2.2.0
I found the problem it is permision of each files now it seem to work I will connect with CAN network and see if everythink working and I will leave info here.
Other question there is no installation procedure only copying of unpacked files to the destination folder?
Correct.
OK now after changing permition everything working.
Thank you for your good job
This worked great, the first time. Thanks for the info! Sure a lot better than having to build the whole kernel from scratch like the “old” days…
The procedure works well for Wheezy (thank you for this, the kernel recompile procedure was quite an ordeal), do you know if this will work under Jessie as well?
Not tried Jessie.
Followed exactly as is, but I’m seeing this error in dmesg when I send a message (and message is not sent according to CAN Bus analyzer):
mcp251x spi0.0: unable to set initial baudrate!
mcp251x spi0.0: can0: bit-timing not yet defined
Anyone know of any solution to this? Running on RPi 2. Thanks
Check you have edited the /boot/config.txt file correctly.
I had the same issue on my Rpi2. Had to run the command:
sudo /sbin/ip link set can0 up type can bitrate 500000
How does the ./cansend work?
If I set baudrate to something different than 500000 in “sudo /sbin/ip link set can0 up type can bitrate 500000″, it seems to me like cansend transmit messages onto the canbus forever (have to stop it by “/sbin/ip link set can0 down”. With 500000 cansend transmits only once (which I expect is the way it should be).
Regarding “How does the ./cansend work?”
Found the source and downloaded it by:
sudo git clone https://github.com/linux-can/can-utils.git
Then compiled and built it by:
cd can_utils
sudo make
My system:
Linux raspberrypi 3.18.11-v7+ #777 SMP PREEMPT Sat Apr 11 17:30:37 BST 2015 armv7l GNU/Linux
Hello,
When I try the sudo /sbin/ip link set can0 up type can bitrate 500000 the I get the Cannot find device “can0″ message.
Please help.
Thx!
pi$ sudo /sbin/ip link set can0 up type can bitrate 500000
Cannot find device “can0″
Any idea how to do debug whats wrong?
I have verified everything is good in /boot/config.txt
Installed everything on a Raspberry Pi 2, and it takes all commands, no errors. My problem is that nothing seems to work. Nothing in Wireshark, and no level changes on an oscilloscope. After attempting to send data with cansend several times, I will eventually get an error: write: No buffer space available I will have to reboot the Pi to clear it, and start again. I reboot, but it just repeats the cycle. LED1 is lit on the PiCAN, if that helps any. I am trying to use the PiCAN as a ‘master’ driving the CAN bus, sending data to a device, so I have no way of just watching traffic on an existing bus.
Also, trying to talk on a low speed bus, 125k. I imagine this command is correct:
sudo /sbin/ip link set can0 up type can bitrate 125000
I have tried the recommended:
sudo /sbin/ip link set can0 up type can bitrate 500000
But I still get no results, according to the oscope. Anything you can suggest would be most helpful. Thanks!
What device are you connecting to? Make sure the baud rate matches. Also you may need to enable the terminator, just close JP3.
Jumped JP3, and that did have an effect. I now get some traffic. What I now notice is that using ./cansend can0 20B#6100 sends data for several seconds, instead of just sending quickly, and then stopping. It’s as if it is either sending several times, or it is initiating bus activity, and sending very slowly. Nothing registers in Wireshark, despite being open and supposedly capturing can0. If you try to send again, it yields no additional response, as if no command had been sent, and the bus stays ‘silent’. After sending 3-4 more times, it gives the same write error, and then effectively locks up until I reboot.
In short, the termination resistor at least shows it wants to work, but still have a bit more to work out. Any suggestions you can offer will be most welcome. Thanks!
Check you have configured Wireshark correctly. Check the baud rate matches the device you are connected to.
Check CAN_L and CAN_H is not swapped.
is it possibile to use with CANopenNode or Canfestival?
Hi,
is there any info what GPIO pins doest it use? I want to use it with my RP2, but I also need to keep free as many GPIO pins as possible. So which ones does it need to be connected in order to behave correctly?
Thanks a lot.
Rad
Hi,
Is it possible to connect two PiCAN boards to my raspberry?
Thx!
Regards,
Zol
Possible, you can stack one board on the top. You need to move the CS line on the second board to CE1. The driver would also need to be updated.
Could you explain how can I update the driver?
Regards,
Zol
Which side of the SJ1, SJ2, SJ3 solder points do I use for the DB-9 connector. The schematic seems to indicate left on SJ1 and SJ2 and right on SJ3. Also, I can’t find JP3 on the schematic. What is it used for?
You need to solder the left handside soldier bridges.
Check this page for more details:http://skpang.co.uk/catalog/canbus-breakout-board-p-754.html
JP3 is for the terminating resistor.
after an rpi-update today (26 July 2015) to kernel 4.0.7, the PICAN board failing to work.
Has anyone else been able to successfully use 4.0.7
Also, one needs to drop the -overlay in the /boot/config.txt settings, so that it reads:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835
according to https://github.com/raspberrypi/firmware/tree/master/boot/overlays
Thanks
Bart
did sudo rpi-update again, and firmware is now 4.0.9-v7+
dmesg reports:
[...] mcp251x spi0.0: can0: bit-timing not yet defined
[...] mcp251x spi0.0: unable to set initial baudrate!
[...] mcp251x spi0.0: can0: bit-timing not yet defined
[...] mcp251x spi0.0: unable to set initial baudrate!
…
/boot/config.txt is what it states above.
I have tried with other PICAN’s and RPi’s, same issue.
I might have found the issue:
in raspi-config, overlocking, set to ‘Pi2′
This appends 3 lines to config.txt
core_freq=500
sdram_freq=500
over_voltage=2
I got it working today with:
$ uname -a
Linux pi 4.0.9-v7+ #807 SMP PREEMPT Fri Jul 24 15:21:02 BST 2015 armv7l GNU/Linux
/boot/config.txt is as the instructions indicate:
dtparam=spi=on
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
I didn’t do any overclocking.
It appears to work fine when the Pi has an ethernet network connection, but not over wifi. As soon as I bring up the CAN interface with:
/sbin/ip link set can0 up type can bitrate 500000
it takes down the wlan0 interface. I have no idea why that is, and am looking for suggestions.
Hi, does this “new” method work also on RPI B+, or is it just for RPI 2? I am trying to reproduce it on B+, but keep getting messages
[ 854.333249] mcp251x spi0.0 can0: bit-timing not yet defined
[ 854.333300] mcp251x spi0.0: unable to set initial baudrate!
in dmesg.
$ uname -a
Linux rpi-pwm02 4.1.5+ #809 PREEMPT Thu Aug 13 00:30:15 BST 2015 armv6l GNU/Linux
Thanks
Ota
Now I can see the messages from my prevous message seems to be normal. But after following debugging, I found out that
$ ip -d -s link show can0
shows in the beginning:
can state ERROR-ACTIVE
but after sending a message or if there is some communication on the bus it changes to:
can state ERROR-PASSIVE
The complete can state is:
$ ip -d -s link show can0
3: can0@NONE: mtu 16 qdisc pfifo_fast state UP mode DEFAULT qlen 10
link/can
can state ERROR-PASSIVE restart-ms 0
bitrate 500000 sample-point 0.875
tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 8000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 4 4 1
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 1 1 0 0
Do You have any more hints, what else to check?
I am feeling completely stuck….
Thanks in advance!
Ota
I got the same problem here.
Have you got it solved, Ota?
My problem has been fixed.
I am now able to send and receive between PiCAN and Tiny-CAN.
The problem was I connected the cable to ODBII instead of CAN_H and CAN_L and I set the wrong baudrate.
Just for the update.
Hello,
how is it possible to change the physical adress from the device “can0″? If I type “ifconfig”, the hardware adress is always “00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00″. How can ich change this?
Thanks
Andy
I seem to be stuck in a *similar* area.
environment:
Raspberry Pi 2 Model B Rev 1.1
Linux raspberrypi 4.1.6-v7+ #810 SMP PREEMPT Tue Aug 18 15:32:12 BST 2015 armv7l GNU/Linux
usage:
marine (raymarine) can net environment
after executing:
ip link set can0 up type can bitrate 500000
and executing: ip -s link show can0
3: can0@NONE: mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
dmesg show:
[ 125.586532] mcp251x spi0.0 can0: bit-timing not yet defined
[ 125.586558] mcp251x spi0.0: unable to set initial baudrate!
I tried different a bitrate, etc and anything else I can find (aside from going back to a specific firmware and build) but have never got it to work. I wish I had a way to minimally know the pican board is good.
Another clue: when I try to bring the port up with: ‘ ip link set can0 up type can bitrate xxxxxxx
‘, it brings the seaTalk bus down until I either delete the device or reboot rpi. (The device becomes ‘busy’ and trying to put it in a ‘down’ state is futile).
If you have any suggestions and or comments please forward on. Thanks!!
Marty…