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

SPI Device

  • VikTan

    VikTan - 2015-11-01

    How can I create a new device? I need to make communication between RasPi and my board through SPI port. There is an example for device MCP3008 but I can't find the way how to modify it

  • eschwellinger

    eschwellinger - 2015-11-01


    see the documentation here for details:

    "c:\Users\YourWindowsUsername\CODESYS Control for Raspberry PI\\DataSheet\RaspberryPI_en.pdf"

    The devices and libraries which you could use as startpoint are here:
    "c:\Users\YourWindowsUsername\CODESYS Control for Raspberry PI\\Devices"
    "c:\Users\YourWindowsUsername\CODESYS Control for Raspberry PI\\Libraries"


  • VikTan

    VikTan - 2015-11-04

    There are examples good for startpoint overview, but now I want to create my own device for my own board with some binary IO. Is there any way to create a new device?

  • VikTan

    VikTan - 2015-11-04

    Ok, I got it, this pdf, page 17

  • VikTan

    VikTan - 2015-11-05

    I work around IoDrvPiFace a and I trying to change channels in "SPI devices I/O Mapping". What is the way to do it? In method "IoDrvUpdateConfiguration" is part:

       //Setup I/O area
       pParameter := IoMgrConfigGetParameter(m_pConnector, 1000);      (* inputs *)
       IF (pParameter <> 0) THEN
          pParameter^.dwDriverSpecific := 0;               (* Device offset 0 *)
       pParameter := IoMgrConfigGetParameter(m_pConnector, 2000);      (* outputs *)
       IF (pParameter <> 0) THEN
          pParameter^.dwDriverSpecific := 0;               (* Device offset 0 *)

    In pdf "Creating own Runtime System Components and I/O Drivers" on page 12 is:
    but after modifying this values, in project nothing was change, I want to add some IO bytes more.


  • VikTan

    VikTan - 2015-11-06

    Maybe it is not easy to understand what I need. So, can someone add an input or outbut byte in IoDrvPiFace.library? I need to see it in SPI Devices IO Mapping.

    Thanks, Viktor

  • VikTan

    VikTan - 2015-11-11

    No answer
    I believe anyone want to to help but its not clear what I want.

    At first, we are developing control system based on Raspberry Pi and additional FPGA boards. Its mean mainly for cnc controller LinuxCNC but we looking for additional field of use of same hardware. We are done with IO binary board (16inputs/16outputs) and I trying to make IO driver for Codesys. More info about system for LinuxCNC:

    It is possible to help me and show how to modify and add some more I/O which are visible in

  • eschwellinger

    eschwellinger - 2015-11-30

    Hi VikTan,

    if you want provide an SPI Driver for your device you need to add your library and your devicedescription for your device.
    Maybe PiFace_Io_driver is the startpoint you need.
    In the device description which you find here:
    "c:\Users\<yourwindowsusername>\CODESYS Control for Raspberry PI\\Devices\PiFaceIOdrv.devdesc.xml"
    library here:
    "c:\Users\<yourwindowsusername>\CODESYS Control for Raspberry PI\\Libraries\IoDrvPiFace.library" </yourwindowsusername></yourwindowsusername>

    This documentation for the runtime toolkit is not really useful for adapting Drivers for raspberry pi, this is more or less used if you buy the toolkit
    and adapt a driver in C.

    This SPI/I2C and other devices are implemented in IEC Code and need additional a devicedescription.
    For Information on how to develop IEC libraries see the Store pdf and additional the FAQ section here in the Forum for best practice on
    how to devel libraries (two instances on opens the library the second CODESYS instance open the project and test/debug your code even step into the library is possible )


  • VikTan

    VikTan - 2015-12-01

    Hi, thanks for answer

    I already tried all this steps what you wrote. Something if working something not.
    Consider the example, original PiFace_IO_Driver:
    Is it possible to add some new variable by editing PiFaceIOdrv.devdesc.xml or IoDrvPiFace.library?

    I assume yes and for someone who are experienced in codesys is it question of few steps and few minutes.
    If someone can, pls describe me how to add any variable to this place. Step by step or something in particular what can help me to move to forward, not only general here is examples good for start.

    Thank you in advance for any help

    IMG: codesys_add_io.png

  • eschwellinger

    eschwellinger - 2015-12-03

    Hi VikTan,

    give me some time to generate some more documentation for this..

  • VikTan

    VikTan - 2015-12-03

    I'll be very grateful

  • yyannekk

    yyannekk - 2016-03-07

    I am facing the very same situation as OP.
    I want to add interface variables (IO Mapping) but don't know how to to that.
    Did someone update the documentation? If yes where to find it?

  • VikTan

    VikTan - 2016-03-16

    I want to add interface variables (IO Mapping) but don't know how to to that.

    Edwin helps me with some points. Here is simple modified program PiFace with added variables.
    Look mainly to "IoDrvReadInputs" and "IoDrvWriteOutputs" there is connection between project and library


  • bnjroos

    bnjroos - 2016-11-29

    Hello VikTan,

    Your link seems dead, would it be possible for you to repost it ? I am in a similar situation and that would be of great help, I need to develop a SPI library for a raspberry hat in order to use it with codesys and I am a bit confused on how to do it.

    Thank you in advance,

  • VikTan

    VikTan - 2017-05-13

    Old link on dropbax is dead, I will add one what will work. This is modified PiFace driver communicating with board PiDiCNC via SPI
    https://youtu.be/G4Is4D764dU m


Log in to post a comment.