CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Aug 20, 2019 6:10 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 65 posts ]  Go to page Previous 1 2 3 4 5 Next
Author Message
 Post subject: Re: CAN trough SPI ?
PostPosted: Mon Apr 11, 2016 5:31 pm 
Offline

Joined: Thu Jul 30, 2015 7:22 pm
Posts: 2
Hi guys,
For me it works on a Pi2 but I was helped from Codesys support team, thanks to them !

Please if you need help be more specific and tell which step is not working for you, etc.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Mon Apr 11, 2016 5:34 pm 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
What process did you follow to get it to work on a P2?


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Tue Apr 12, 2016 4:46 am 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
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
sudo reboot.

2. Now your raspbian is update and upgrade with the lastet version, you can using uname -a to check the version of your raspbian
Returned: 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

cd /
sudo tar -xjf ~/rpi-can-3.18.7+.tar.bz2
sudo depmod -a
sudo reboot
didn'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:

spi_bcm2835

spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release

mcp251x

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 sites
http://tiqni.com/raspberry-pi/can-bus-s ... spberry-pi

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

add in
/etc/CODESYSControl.cfg

[ComponentManager]
Component.1=CmpOpenSSL
Component.2=CmpCAACanL2
Component.3=CmpCAASdoServer
Component.4=CmpCAASdoClient
Component.5=CmpSocketCanDrv

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

#!/bin/sh
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)

sudo /root/rts_set_baud.sh

20. Enter below code

#!/bin/sh
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


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Tue Apr 12, 2016 4:51 am 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
OK. Looks like I might have it. I replaced the 8mhz crystal on the can hardware to 16mhz and Its transmitting a heart beat which I am reading from another can sniffer. No I need to figure out how to create custom messages. I'd like to communicate to an arduino using the same hardware and trigger it to turn on and off outputs as well as setting pwm signals. just need to figure out how to use the messages to do that.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Thu Apr 14, 2016 2:54 am 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
OK. Now Im trying to write code to read all messages on the J1939 Canbus. How do I go about doing that?
I looked at the example but I couldnt figure out how it is linked to the canbus module. does anyone have any other example code I could look at?


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Thu Apr 14, 2016 4:31 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3387
Hi,
according your ardoino question check the example here (Layer2 communication) http://store.codesys.com/mixedsearch/mi ... duct_area=
and J1939 see screenshot.
BR
Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Thu Apr 14, 2016 10:30 am 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
I looked at the example code but I am unable to determine how the code is linked to the specific J1939 ecu in the tree.

Also, If the CAN messages are controlled within the program, Why is there a spot to select TX and RX PNG messages in the device?

Is there a manual on how to use CAN with Codesys?


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Thu Apr 14, 2016 6:17 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3387
Hi,
sorry to confuse you with that.

The device tree screenshot is not relatet with the store example.
CANApi projct from store is for CAN Layer 2 communication.

J1939 from my screenshot is only to Show how to configure J1939 devices by this configurator pages

BR
Edwin


Last edited by Edwin Schwellinger on Fri Apr 15, 2016 7:07 am, edited 1 time in total.

Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Thu Apr 14, 2016 10:26 pm 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
Edwin,

Is it possible to write a small example for me to read and write a j1939 message using CANpi. I am still confused with using the TX RX entries in the device tree.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Apr 15, 2016 7:17 am 
Offline

Joined: Sun Aug 21, 2011 8:33 pm
Posts: 18
http://www.industrialberry.com/can-bus-with-codesys/
they have RPI+CANbus work with codesys. is possible also work with CANopen to add device CANopen?


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Apr 15, 2016 7:41 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3387
sure if this implementation is stable (SocketCAN)
you could use:

Pi as CANopen Master is possible
Pi as CANopen Slave is possible
Pi using for CAN Layer 2 communication (Store CAN API example)
Pi using J1939

BR
Edwin


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Apr 15, 2016 1:45 pm 
Offline

Joined: Thu Feb 11, 2016 4:06 am
Posts: 38
Edwin,

Can you please Explain when you would use all the PNG RX and TX messages in the device tree under the can ecu module?

Can you explain the different ways of communicating over CAN with the Pi? You talked about layer 2 which I assume is a level in which all message transactions are performed on a software level within the codesys program. There does however look to be another layer inwhich you can use the RX and TX PNG messages directly within the device tree. Can you explain the difference and how to use the device tree message selections?


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Tue Jun 28, 2016 3:01 pm 
Offline

Joined: Sun May 29, 2016 9:44 pm
Posts: 15
i have raspberry pi 3 with pican 2 rev B i make all setting but the can interface i don't see in cosesys , i check the can interface with candump and receive all packet
Please help me to config can interface


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Mon Oct 03, 2016 3:15 am 
Offline

Joined: Fri Aug 19, 2016 7:36 pm
Posts: 3
First, thank you to all of you have contributed to this thread. Using this, I am able to mostly get everything working. I am using RPI3 and Codesys v3.5 sp9 sp1 and the PiCAN2.

I have a CANOpen bus coupler and have installed the manufacturers EDS file. The Canbus and CANOpen_manager run fine.
However, when I try to run the Can slave device, I get the following errors.
Any advice on how to trouble-shoot this?
Attachment:
rpi12016-10-02_18-59-34.jpg


Any advice/suggestions on where to get started?


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Mon Oct 03, 2016 6:44 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3387
Hi,
please set the Compiler define: CANOPEN_DEBUG
After that (compile,download,start the project) check the plc logger for more CANopen debug Information

BR
Edwin


You do not have the required permissions to view the files attached to this post.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 65 posts ]  Go to page Previous 1 2 3 4 5 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited