Driver Documentation
Database
This documentation describes the process of creating an own SPI driver for CODESYS, based on the SPI Template, which can be found in the Code Repository. The driver consists of a "Device Description" as well as a CODESYS Library. All essential settings in the Library or the Device Description are repeated in this documentation. For more detailed informations about the Device Descriptions, please check the general I/O driver documentation.
You can use a copy of the Device Description "SPI_Template.devdesc.xml" as a starting point. You need to adapt the following sections of the device description for your needs.
<DeviceDescription>
...
<Device>
...
<DeviceIdentification>
...
<Type>501</Type>
...
</DeviceIdentification>
...
</Device>
...
</DeviceDescription>
<DeviceDescription>
...
<Device>
...
<DeviceIdentification>
...
<Id>0003 0001</Id>
...
</DeviceIdentification>
...
</Device>
...
</DeviceDescription>
<DeviceDescription>
...
<Device>
...
<DeviceIdentification>
...
<Version>1.0.0.0</Version>
...
</DeviceIdentification>
...
</Device>
...
</DeviceDescription>
The connector describes the node in the device tree, which the user sees after he added your device. The I/O driver will search for this connector.
<DeviceDescription>
...
<Device>
...
<Connector moduleType="500" interface="Raspberry.SPI" ...>
...
...
</Connector>
...
</Device>
...
</DeviceDescription>
<DeviceDescription>
...
<Device>
...
<Connector moduleType="500" interface="Raspberry.SPI" ...>
...
...
</Connector>
...
</Device>
...
</DeviceDescription>
This section specifies some parameters of the driver, and in our case, also which library should be used.
<DeviceDescription>
...
<Device>
...
<Connector moduleType="500" interface="Raspberry.SPI" ...>
...
<DriverInfo needsBusCycle="false">
...
<RequiredLib libname="SPI Template" vendor="Open Source" version="1.0.0.0" identifier="SPI Template">
...
</RequiredLib>
...
</Parameter>
...
</Connector>
...
</Device>
...
</DeviceDescription>
<DeviceDescription>
...
<Device>
...
<Connector moduleType="500" interface="Raspberry.SPI" ...>
...
<DriverInfo needsBusCycle="false">
...
<RequiredLib libname="SPI Template" vendor="Open Source" version="1.0.0.0" identifier="SPI Template">
...
<FBInstance basename="$(DeviceName)" fbname="SPITemplate">
...
<Initialize methodName="Initialize" />
<CyclicCall methodname="AfterReadInputs" task="#buscycletask" whentocall="afterReadInputs" />
<CyclicCall methodname="BeforeWriteOutputs" task="#buscycletask" whentocall="beforeWriteOutputs" />
...
</FBInstance>
...
</RequiredLib>
...
</Parameter>
...
</Connector>
...
</Device>
...
</DeviceDescription>
The host parameter set defines all your configuration parameters, as well as I/O channels. In the current SPI interface, you can use configuration parameters, but no I/O channels.
The configuration parameters can be read in the library within the function "Initialize".
<DeviceDescription>
...
<Device>
...
<Connector moduleType="500" interface="Raspberry.SPI" ...>
...
<HostParameterSet>
...
<Parameter ...>
...
</Parameter>
...
</Connector>
...
</Device>
...
</DeviceDescription>
For more information about the HostParameterSet and datatypes, please check the general I/O driver documentation.