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 Wed Oct 16, 2019 10:17 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 65 posts ]  Go to page 1 2 3 4 5 Next
Author Message
 Post subject: CAN trough SPI ?
PostPosted: Thu Feb 13, 2014 9:18 pm 
Offline

Joined: Wed Feb 12, 2014 9:00 pm
Posts: 7
Is there(or will there ever be?) any mean to use CAN with an expansion board like this one : http://www.industrialberry.com/can-controller/

with the raspberry pi and CodeSys?

I think this would be a pretty awesome feature

Also is there any mean to programm custom SPI libraries(i'm thinking of making an ADC board and use analog inputs in codesys logic)

THanks for this great product!


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Wed Feb 19, 2014 11:01 am 
Offline

Joined: Thu Sep 18, 2008 1:31 pm
Posts: 27
I suggest to the developers to seriously think about making CAN/CANOpen supported in some way or another too.
Both for educational purposes (for the "Teaching" part in "Raspberry Pi Teaching Platform") and for purposes of actually using this in automotive and other fields, where CAN slaves are either already present as a standard or cheaply available.

ProfiBus/Profinet solutions on the other hand tend to be rather expensive (compared to CANOpen counterparts) due to licensing etc. At least in my personal experience.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Wed Feb 19, 2014 12:54 pm 
Offline

Joined: Wed Feb 12, 2014 9:00 pm
Posts: 7
And its also easy to build your own messages to communicate on a higher layer protocol (thinking of J1939 and CANopen(if just sharing PDO) )

I played a little bit with codesys 3, i use Codesys 2.5 at work everyday, i think the J1939 Library seems pretty awesome, it gives you the latitude to configure custom messages wich is good, but could we get to lower layer with the pi and just send and recieve raw CAN messages?


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Sun Aug 03, 2014 5:27 pm 
Offline

Joined: Wed Feb 12, 2014 9:00 pm
Posts: 7
While working woth codesys 3.5 on the new ECU I'm using at work, I understood that if the CAN driver is integrated at the system level you can use it directly in codesys with the low-level coding.


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Sun Aug 03, 2014 6:30 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3491
Hi,
if anyone manage to build his own Linux kernel with socketcan support,
this will work with the 3S runtime. The needed parts in the runtime are in.
And if you have socketcan running, even J1939 will work out of the box, everything needed is on board in CODESYS IDE

BR
Edwin


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Aug 29, 2014 1:49 am 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
Edwin,

I managed to find a SPI Can Module that works with the PI

http://www.mikroe.com/click/pi-shield/
http://www.mikroe.com/click/can-spi-3.3v/

Using the following I got the SPI to show up as an socketcan adapter by using the following steps

http://lnxpps.de/rpie/

http://tech.enekochan.com/en/2014/03/08/upgradedowngrade-to-a-specific-firmware-kernel-version-with-rpi-update-in-raspbian/
#Need to downgrade to match copied modules raspberrypi 3.12.22+
sudo rpi-update bfd37013c701f10c6df585346ee1d3d3bdf88b3b
cd /tmp; wget http://lnxpps.de/rpie/rpi-can-3.12.22+.tar.bz2
# untar the archive:
cd /; sudo tar jxvf /tmp/rpi-can-3.12.22+.tar.bz2 # you normally should'nt do that
# register modules:
sudo depmod -a
# and do a
sudo reboot

modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
modprobe spi-bcm2708
modprobe can
modprobe can-dev
modprobe can-raw
modprobe can-bcm
modprobe mcp251x
ip link set can0 up type can bitrate 250000
service codesyscontrol start

Attachment:
SPI Can.jpg


What I can not get working is CoDesys to recognize the PI to have CAN. Whenever I add the CanManager it will give me compile message that the hardware does not match the controller.

Attachment:
SPI Can2.jpg


Thanks


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

_________________
The Original SoMachine Ninja


Last edited by jzhvymetal on Fri Aug 29, 2014 7:12 am, edited 2 times in total.

Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Aug 29, 2014 6:34 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3491
Hi,
Thanks for reporting this,
could you give me the messages from the plc log?
Regards
Edwin


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Aug 29, 2014 6:59 am 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
Edwin,

As requested here are the attached log files. To give you more info I am still using demo version codesyscontrol_V3.5.4.0.deb. I also noticed I was not loading all the modules required for SocketCan. Please notice I updated the steps up above along with the Dmesg output screenshot. Also I do not load the codesyscontrol service until all modules are loaded. Let me know if you need any further information.

_________________
The Original SoMachine Ninja


Last edited by jzhvymetal on Sat Aug 30, 2014 12:51 am, edited 1 time in total.

Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Fri Aug 29, 2014 10:32 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3491
Hi,
please use the 3.5.5.0 version of the runtime, then it might work, to be honest I did test it but I will do it.
Best regards
Edwin


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Sat Aug 30, 2014 12:09 am 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
Same problem using CODESYS_3.5SP5Patch1_Release and Raspberry Pi CoDeSys Control Version: 2.0.0.0 aka codesyscontrol_arm_raspberry_V3.5.5.0.deb. See Attached PLClogs. FYI I know cansocket is working because I can use candump and monitor traffic off a PLC with CanOpen master.

Do you have to add any additional components under ComponentManager section in CODESYSControl.cfg?


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

_________________
The Original SoMachine Ninja


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Tue Sep 02, 2014 7:46 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3491
Hi,
you need to add the Component 2-5 into
/etc/CODESYSControl.cfg

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

If you have a running SocketCAN implementation in your Linux Kernel, this should work.
(This is not the case in the delivered standard wheezy image which comes with the store download!)

Regards
Edwin


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Wed Sep 03, 2014 12:02 am 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
Edwin,

Now I can download to the PI without error but Canbus still does not work. See attached PLClog. It gives Script: rts_set_baud.sh not found- can 0 will not work.

With CanSocket I bring up the Canbus and match the bus speed used in the Codesys program. This is the command I use to bring up the adapter:

ip link set can0 up type can bitrate 250000

Also I have disable the Codesyscontrol service on boot up. If I don't CanSocket will not load because Codesyscontrol locks control. I believe is caused by Codesyscontrol locking out SPI driver. If I load CanSocket first then start Codesyscontrol it will let me download but as above Can still is not working.


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

_________________
The Original SoMachine Ninja


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Wed Sep 03, 2014 6:18 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3491
Hi,

beside the problem with the baudrate script, which we could workaround with using the same baudrate as you set with ip link set can0 up type can bitrate 250000.

This line with the missing license file may lead to the read triangle in the device tree on the left side and maybe to an
not working CAN.
How do you start the plc manually it seems that the runtime does not find the licensefile?

BR
Edwin


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Wed Sep 03, 2014 1:10 pm 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
Edwin,

I am still using the demo version. I can purchase a license if required. Right now I am playing with different images and different PI's. My plan was to buy a license once I get Canbus working. This way I do not have keep moving the license when using a new image or PI.

I have to done the following:

#1 Disable codesyscontrol at boot up
#This was required because CanSocket does not want to load if codesyscontrol is first loaded
sudo update-rc.d codesyscontrol disable
reboot

#2 Load all required drivers and start CanSocket
modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
modprobe spi-bcm2708
modprobe can
modprobe can-dev
modprobe can-raw
modprobe can-bcm
modprobe mcp251x
ip link set can0 up type can bitrate 250000

#3 Start codesyscontrol
service codesyscontrol start

#4 From windows download the codesys program with Canbus->Canopen Manager

#5 Start PLC from windows codesys

_________________
The Original SoMachine Ninja


Top
   
 Post subject: Re: CAN trough SPI ?
PostPosted: Wed Sep 03, 2014 1:36 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3491
Hi,

no, you do not need to purchase a license, but please use 3.5.5.0 because then you have the same
version that I use and in my case I do not see the error in the log: license file missing - License File missing -> think fieldbus will not work
even not in Demo mode.

The limitation of the demo pi runtime is:
All fieldbus feature are running but the runtime quits after 2h of working in full mode.
So for sure you do not need to buy a license for our tests.

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 1 2 3 4 5 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 8 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