Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

CAN trough SPI ?

Rotule
2014-02-13
2022-07-12
<< < 1 2 3 > >> (Page 2 of 3)
  • eschwellinger

    eschwellinger - 2014-10-01

    hi,

    Wow, this sounds good!
    Meanwhile a second user verified that loss of can messages is solved by using the description.

    BR
    Edwin

     
  • alex87 - 2014-11-03

    jzhvymetal,

    Have you get the CanOpen fully working on your Codesys raspPI? If yes what is the right procedure. Im strugling with my PICAN ( w www.skpang.co.uk w ) classic SPI mcp2515 controller.
    I can get the RxTx messages in terminal, so what is the next procedure?
    How to implement it with Codesys do i need any script? I don't understand the implementation with codesys quite well...

    regards,
    Alex

     
  • jzhvymetal - 2014-11-04

    Alex,

    Yes CAN bus is fully working with the PI. I had to use a modified mcp2515 driver to prevent communication from dropping out. Download the attachment from above it gives you step by step procedure required to get CAN bus working with CoDeSys

     
  • maauto - 2014-11-05

    Is there any plan on integrating this patch into the official codesys-store available image soon ? (Since it's been confirmed to be a working solution.)

    Cheers

     
  • eschwellinger

    eschwellinger - 2014-11-07

    Hi,

    at the moment not, is there anyone who want to provide us with an additional debian package
    which add the CAN support?

    BR
    Edwin

     
  • johnlee - 2015-01-07

    Hi jzhvymetal,

    Do you mind to sharing the wiring connection between Raspberry PI+ with the CAN SPI over here?

    Thank you.
    John lee

     
  • johnlee - 2015-01-21

    hi jzhvymetal,

    Thank you for your information. I'm going to test out the circuit and let your all know the status.

     
  • KennyD - 2015-02-01

    Hi all,

    I tried to make the CAN run on the rpi using the following instructions posted by jzhvymetal. THX, in advance, the guidance helped a lot My problem now is that I could not load the drivers on the rpi. If I follow the last steps of the guidance I have to load the drivers using these lines, but a few of the commands returned errors

    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/kernel/drivers/spi/spi-bcm2708.ko realtime
    Error: could not insert module /lib/modules/3.12.28+/kernel/drivers/spi/spi-bcm2708.ko: File exists
    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/kernel/net/can/can.ko
    Error: could not insert module /lib/modules/3.12.28+/kernel/net/can/can.ko: File exists
    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/kernel/drivers/net/can/can-dev.ko
    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/kernel/net/can/can-raw.ko
    Error: could not insert module /lib/modules/3.12.28+/kernel/net/can/can-raw.ko: File exists
    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/kernel/net/can/can-bcm.ko
    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/extra/spi-config.ko
    pi@raspberrypi ~ $ devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
    pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.28+/kernel/drivers/net/can/mcp2515.ko
    pi@raspberrypi ~ $ ip link set can0 up type can bitrate 250000 restart-ms 100 triple-sampling on
    Cannot find device "can0"

    Checking the kernel log afterwards, I got these:
    ...
    Jan 24 14:22:00 raspberrypi kernel: [ 5.331639] bcm2708_spi bcm2708_spi.0: DMA channel 4 at address 0xf2007400 with irq 20
    Jan 24 14:22:00 raspberrypi kernel: [ 5.527024] bcm2708_spi bcm2708_spi.0: DMA channel 5 at address 0xf2007500 with irq 21
    Jan 24 14:22:00 raspberrypi kernel: [ 5.780079] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
    Jan 24 14:22:00 raspberrypi kernel: [ 5.959039] bcm2708_spi bcm2708_spi.0: SPI Controller running in dma mode
    Jan 24 14:22:00 raspberrypi kernel: [ 6.368107] bcm2708-i2s bcm2708-i2s.0: Failed to create debugfs directory
    Jan 24 14:22:00 raspberrypi kernel: [ 10.740693] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
    Jan 24 14:22:00 raspberrypi kernel: [ 11.321773] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
    Jan 24 14:22:00 raspberrypi kernel: [ 12.303374] bcm2708_i2c_init_pinmode(1,2)
    Jan 24 14:22:00 raspberrypi kernel: [ 12.312180] bcm2708_i2c_init_pinmode(1,3)
    Jan 24 14:22:00 raspberrypi kernel: [ 12.324416] bcm2708_i2c bcm2708_i2c.1: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
    Jan 24 14:22:00 raspberrypi kernel: [ 12.480642] pcm512x 1-004d: Failed to reset device: -5Jan 24 14:22:00 raspberrypi kernel: [ 12.480767] pcm512x: probe of 1-004d failed with error -5Jan 24 14:22:00 raspberrypi kernel: [ 12.481175] pcm512x 1-004c: Failed to reset device: -5Jan 24 14:22:00 raspberrypi kernel: [ 12.481269] pcm512x: probe of 1-004c failed with error -5
    Jan 24 14:22:00 raspberrypi kernel: [ 12.541974] i2c /dev entries driver
    Jan 24 14:22:00 raspberrypi kernel: [ 17.957006] FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
    Jan 24 14:22:00 raspberrypi kernel: [ 20.595928] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
    Jan 24 14:22:00 raspberrypi kernel: [ 22.231989] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0x41E1
    Jan 24 14:22:00 raspberrypi kernel: [ 86.140630] Driver for 1-wire Dallas network protocol.
    Jan 24 14:22:00 raspberrypi kernel: [ 86.160779] w1-gpio w1-gpio: gpio pin 4, gpio pullup pin 1
    Jan 24 14:22:02 raspberrypi kernel: [ 90.408256] Adding 102396k swap on /var/swap. Priority:-1 extents:1 across:102396k SSFS
    Jan 24 14:22:05 raspberrypi kernel: [ 93.077965] can: controller area network core (rev 20120528 abi 9)
    Jan 24 14:22:05 raspberrypi kernel: [ 93.078154] NET: Registered protocol family 29
    Jan 24 14:22:05 raspberrypi kernel: [ 93.128952] can: raw protocol (rev 20120528)
    ...

    Hope you guys can help me!

    THX in advance
    Stefan

     
  • johnlee - 2015-02-16

    Hi KennyD,

    Can you kindly advice which version of the Linux your using?

    Just for your information, i have using the Linux where given from Codesys Store, and follow the step given by Edwin Schwellinger. I able to get the CAN SPI driver load into the Linux(Without doing the kernel complied).

    But the most difficultly is the step to make the Can Bus attach to the Codesys RunTime.

    As i'm newbie to Linux, it take me a long way walk thru the step given by Edwin Schwellinger.

    However tmr i going to test out the integrated with Codesys Run Time.

    Once i get it will update here again.

    And once again thanks to the jzhvymetal provide me the information of the wiring of the SPI Can, it really helpful.

    John Lee

     
  • jzhvymetal - 2015-02-18

    All make sure you when you initalize you Can Driver you have the clock and IRQ correct. Also make note that when you start a codesys PI program all input pins are assigned directly to CoDeSys. Make sure inside the CoDeSys program to turn off the I/O assigned to IRQ PIN.

    The click board uses the following
    http://www.mikroe.com/click/pi-shield/
    http://www.mikroe.com/click/can-spi-3.3v/

    IRQ PIN=17
    CLOCK=10Mhz

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

    This link http://lnxpps.de/rpie/ circuit uses the following
    IRQ PIN=25
    CLOCK=16Mhz

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

     
  • Giulix72 - 2015-02-27

    Hi to all,
    I simple question. With the experience write in this thread, Codesys can send only raw can bus message or can use the Codesys also the canopen protocol ?
    In other words, If I want to communicate with a standard DS401 canopen I/O module, it is possible ?

    Also if I have nr 3 DS402 servodrive it is possible to use Softmotion CNC to make 3D path (example 3 axis CNC milling machine)?

    THanks
    Giuliano

     
  • eschwellinger

    eschwellinger - 2015-02-27

    Hi>Zitat:
    ,
    I simple question. With the experience write in this thread, Codesys can send only raw can bus message or can use the Codesys also the canopen protocol ?

    CANopen protocol

    Zitat:
    In other words, If I want to communicate with a standard DS401 canopen I/O module, it is possible ?

    yes

    Zitat:
    Also if I have nr 3 DS402 servodrive it is possible to use Softmotion CNC to make 3D path (example 3 axis CNC milling machine)?

    no, missig a realtime Linux kernel patch to have realtime capabilities.

    BR
    Edwin

     
  • KennyD - 2015-03-04

    jzhvymetal hat geschrieben:
    All make sure you when you initalize you Can Driver you have the clock and IRQ correct. Also make note that when you start a codesys PI program all input pins are assigned directly to CoDeSys. Make sure inside the CoDeSys program to turn off the I/O assigned to IRQ PIN.
    The click board uses the following
    http://www.mikroe.com/click/pi-shield/
    http://www.mikroe.com/click/can-spi-3.3v/
    IRQ PIN=17
    CLOCK=10Mhz
    modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
    This link http://lnxpps.de/rpie/ circuit uses the following
    IRQ PIN=25
    CLOCK=16Mhz
    modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release

    Hi jzhvymetal,
    I build the following using your post from Tue Sep 30, 2014 7:29 am :
    Linux raspberrypi 3.12.28+ #1 PREEMPT Sat Jan 24 00:05:53 CET 2015 armv6l GNU/Linux

    I'm also able to load all necessary modules to get the device can0. I also use your first named configuration because I use the "CAN SPI Click" board
    modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
    After this I wanna test the CAN connection by using some can tools like cansend or candump, but I can't establish any connection i.e. I could not see any incoming or outgoing CAN messages.

    Could you help me out of this?

    Cheers and many many thanks in advance
    Stefan

     
  • johnlee - 2015-05-04

    Hardware:

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

    Version of Codesys RSPI:
    2.1.1.0, Raspian 3.18

    Precompile Raspian Kernel with SPI CAN driver can download from this website(include different version, just select the version you needed)
    http://ifinterface.com/page/page3.php?langid=1

    You can using usb thumb driver to transfer the files into RSPI via below method
    http://www.raspberrypi-spy.co.uk/2014/0 ... pberry-pi/

    or

    You can using filezila to transfer the files as below method
    http://trevorappleton.blogspot.sg/2014/ ... -your.html

    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.

    1. Now your raspbian is update and upgrade with the lastet version, you can using uname -a to check the version of your raspbian

    2. using one of the above method transfer the precompile kernel files (rpi-can-3.18.7+.tar.bz2) into your /home/pi/

    3. 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

    1. Now your raspbian already have the kernel where support the SPI Can bus.

    2. To let the raspbian everytime startup willl autoload your SPI Can bus do below step

    sudo nano /etc/modules

    1. Enter below code inside it:

      spi_bcm2835

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

      mcp251x

    2. Press Ctrl + o, then press enter to save the files.

    3. Precc Ctrl + x , to exit.

    4. 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.

    5. Above step i refer from this web sites
      http://tiqni.com/raspberry-pi/can-bus-s ... spberry-pi

    6. Now we have follow the step where given from Edwin from Codesys to make the can bus work on the Codesys.

    7. 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

    1. However the latest version of the RSPI Codesys it already enable so you can skip this.

    2. in /home/pi
      sudo nano startplc.sh

    3. 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

    1. Press Ctrl + o , then press enter to save the files. Press Ctrl + x to exit

    2. this stops the runtime, load the modules ,and starts the plc again

    3. additional you need a script in the runtime directory (in our case /root)

    sudo /root/rts_set_baud.sh

    1. 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

    1. press Ctrl + o , then press enter to save the files, press ctrl + x to exit.

    2. Do a reboot, now your good to go.

    3. 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.

    4. I have download the CANBUS example from Codesys Store and tester with above setup. It work well to me.

    Hope above step can help most of them who like to explorer on the CAN BUS with RSPI Codesys.

     
  • yannickasselin1 - 2015-05-07

    Hi everyone,

    I followed all the steps above and CANbus and CANopen_manager seem to work fine but I still cannot communicate with my Festo Servo Drive through CANopen.
    Can someone help me please.

    Here's what it looks like on the Codesys side:

    And on the Festo side:

    IMG: CanFesto.png

    IMG: CanCodesys.png

     
  • Firrel - 2015-07-08

    Hi,
    I tried many different ways how to get CAN working on Raspberry Pi 2 model B with codesys control, but nothing helped.
    Has anyone managed to get it working on rpi 2B and how?

    Zitat:
    Precompile Raspian Kernel with SPI CAN driver can download from this website(include different version, just select the version you needed)
    http://ifinterface.com/page/page3.php?langid=1

    The problem is that the precompiled raspbian kernel does not support raspberry 2.

    My hardware: http://www.rlx.sk/sk/usb-spi-i2c-rs232- ... 1-mbs.html
    Codesys control 35620
    Raspberry Kernel 3.18.7-v7+ (can be upgraded to 4.0.y trough rpi-update)

    Thank you
    Filip

     
  • gry - 2015-08-08

    Hi Firrel,

    I am actually trying same thing.
    From hardware you can try this tutorial http://skpang.co.uk/blog/archives/1165.
    It is not the same board but it is the same chip (mcp2515) so normally it will work fine.

    For me it is both with 4.0.9-v7+ or 3.18.16-v7+ , I can do #cansend from one RPi2 and do #candump from another RPi2, both with a PiCAN board and I see can frames trough CAN bus. Don't forget the 120 ohm resistor on the line.

    For Codesys, I don't actually have but I am working on it, I will post something when it will work.

     
  • stablex - 2016-02-26

    any update?

     
  • johnfarrugia - 2016-04-11

    Does this work on a PI2 or just a PI1?

     
  • gry - 2016-04-11

    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.

     
  • johnfarrugia - 2016-04-11

    What process did you follow to get it to work on a P2?

     
  • johnfarrugia - 2016-04-12

    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.

    1. 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

    2. 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

    3. 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

    1. Now your raspbian already have the kernel where support the SPI Can bus.

    2. To let the raspbian everytime startup willl autoload your SPI Can bus do below step

    sudo nano /etc/modules

    1. 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

    1. Press Ctrl + o, then press enter to save the files.

    2. Precc Ctrl + x , to exit.

    3. 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.

    4. Above step i refer from this web sites
      http://tiqni.com/raspberry-pi/can-bus-s ... spberry-pi

    5. Now we have follow the step where given from Edwin from Codesys to make the can bus work on the Codesys.

    6. 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

    1. However the latest version of the RSPI Codesys it already enable so you can skip this.

    2. in /home/pi
      sudo nano startplc.sh

    3. 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

    1. Press Ctrl + o , then press enter to save the files. Press Ctrl + x to exit

    2. this stops the runtime, load the modules ,and starts the plc again

    3. additional you need a script in the runtime directory (in our case /root)

    sudo /root/rts_set_baud.sh

    1. 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

    1. press Ctrl + o , then press enter to save the files, press ctrl + x to exit.

    2. Do a reboot, now your good to go.

    3. 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.

    4. 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 m

    IMG: Capture.JPG

     
  • johnfarrugia - 2016-04-12

    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.

     
  • johnfarrugia - 2016-04-14

    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?

     
<< < 1 2 3 > >> (Page 2 of 3)

Log in to post a comment.