I tried to get my CAN bus working tonight but no luck.
Here are the steps I followed:
Step to replace kernel files with CAN Bus support :-
1. Make sure your raspbian is the latest version by update and upgrade it
sudo apt-get update
sudo apt-get upgrade
sudo apt-get clean
2. Now your raspbian is update and upgrade with the lastet version, you can using uname -a to check the version of your raspbianReturned: Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux
3. using one of the above method transfer the precompile kernel files (rpi-can-3.18.7+.tar.bz2) into your /home/pi/ Didn't do this because I thought the updates fixed needing to do this now
4. Once your files already copy into /home/pi and do below step
sudo tar -xjf ~/rpi-can-3.18.7+.tar.bz2
sudo depmod -a
sudo rebootdidn't do this
5. Now your raspbian already have the kernel where support the SPI Can bus.
6. To let the raspbian everytime startup willl autoload your SPI Can bus do below step
sudo nano /etc/modules
7. Enter below code inside it:
8. Press Ctrl + o, then press enter to save the files.
9. Precc Ctrl + x , to exit.
10. sudo reboot, when reboot the time if you connect the monitor you can see one of the command is load sucess of the SPI CAN.
11. Above step i refer from this web siteshttp://tiqni.com/raspberry-pi/can-bus-s
12. Now we have follow the step where given from Edwin from Codesys to make the can bus work on the Codesys.
13. As refer older post from Edwin it request us to enable the can bus on /etc/CODESYSControl.cfg as below
14. However the latest version of the RSPI Codesys it already enable so you can skip this.
15. in /home/pi
sudo nano startplc.sh
16. Enter below thing
sudo /etc/init.d/codesyscontrol stop
sudo modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
sudo modprobe mcp251x
sudo ip link set can0 up type can bitrate 250000
sudo ip -s -d link show can0
sudo /etc/init.d/codesyscontrol start
17. Press Ctrl + o , then press enter to save the files. Press Ctrl + x to exit
18. this stops the runtime, load the modules ,and starts the plc again
19. additional you need a script in the runtime directory (in our case /root)
20. Enter below code
BITRATE=`expr $2 \\* 1000`
ifconfig $1 down
echo ip link set $1 type can bitrate $BITRATE
ip link set $1 type can bitrate $BITRATE
ifconfig $1 up
21. press Ctrl + o , then press enter to save the files, press ctrl + x to exit.
22. Do a reboot, now your good to go.
23. I like to modify the files via using nano rather than vi, you can use your own method to modify the files as you want.
24. I have download the CANBUS example from Codesys Store and tester with above setup. It work well to me.
I followed the step by step proceedure except I didnt update the kernal because I was under the impression that the new version of software included the correct kernal.
Any idea what I'm doing wrong? I try to run codesys with the can manager but its not running
I am using a CAN hardware http://www.aliexpress.com/store/product ... eId=627093