Industrial Communications: CAN you do IEC 61131-3 PLC programming with BeagleBone?

Factory automation and control applications used the Controller Area Network (CAN) and CANopen protocols as field buses long before the invention of industrial Ethernet. When used as a communication field bus, these protocols connect the programmable logic controller (PLC) to digital input/outputs (I/Os), motor drives, sensors and actuators.

Bosch developed CAN in 1983. Its initial use case was the communication bus inside of an automobile; it enabled peripherals like the brake system, ignition control and motor to communicate with one another. CAN’s low-cost and robust communication physical layer led to its adoption on the factory floor; CANopen is a specific enhancement of the CAN communication protocol for factory automation. CAN and CANopen are still deployed in many production lines; many manufacturers add the CAN interface to their equipment for compatibility with deployed equipment.

In March, while at the Embedded World trade show in Nuremberg, Germany, I learned that it is very simple to enable industrial International Electrotechnical Commission (IEC) 61131-3 PLC programming on a BeagleBone Black (BBB) using TI’s Sitara™ AM335x processor with an CAN and CANopen communication “cape” or add-on board.

Getting an easy, fast start with the CAN interface and IEC 61131-3 PLC programming is essential for any developer. I find that a BBB is a great platform with which to get started because it runs with Linux, and the CAN tools and CANopen stack are simple to install and well documented. Still, you will have to write the software application that interfaces to the CAN bus.

At Embedded World I visited the 3S booth, the manufacturer of Controller Development System (CODESYS), an industrial IEC 61131-3 PLC programming software program. 3S offers a free evaluation license of CODESYS in their online shop that supports the CAN interface. The evaluation version operates for two hours on the BBB; you can reboot the BBB to restart the two-hour timer. This evaluation version is an ideal starting point to learn about the CAN interface, BBB and the IEC 61131-3 PLC programming language.

So what kind of hardware and software do you need?

You need a BBB, which you can purchase from many electronic component distributors. You also need a CAN interface cape for the BBB, which you can build on your own from the printed circuit board (PCB) design file in TI’s Energy Efficient and Isolated CANopen Interface Reference Design. The CAN cape includes rotary switches and status light-emitting diodes (LEDs).

Figure 1: Isolated CAN reference design PCB used as a transceiver cape for BBB

For software installation, follow the instructions in the design guide of the reference design, which walks you through updating the BBB Linux image, configuring the electrically erasable programmable read-only memory (EEPROM) ID on the CAN cape and testing basic CAN communication.

Next, install the CODESYS runtime software on your BBB. The software package is available on the 3S website. Follow the step-by-step description in the CODESYS for BBB getting started guide.

After that, you will want to make sure that the CAN drivers are loaded at Linux boot time so that the CODESYS runtime software will work with the CAN cape. To do this, edit the file /etc/modules and add the kernel modules can, can-dev, can-raw and c_can_platform. After the modification, the file should look like this:

# /etc/modules: kernel modules to load at boot time.

#

# This file contains the names of kernel modules that should be loaded

# at boot time, one per line. Lines beginning with "#" are ignored.

can

can-dev

can-raw

c_can_platform

Now reboot the BBB to start with CODESYS and IEC 61131-3 PLC programming of the CAN interface.

To test the setup, I used a keypad with a CANopen interface; Figure 2 shows my CODESYS configuration. The green marks indicate that the CAN protocol is operating OK. From here, I can start writing an industrial application by programming in IEC 61131-3 PLC language.

Figure 2: CODESYS device configuration

This was a great learning experience for me, as it was very easy to get the reference design’s isolated CAN cape working on a BBB. Enabling industrial IEC 61131-3 PLC programming through CODESYS is a great way to get started with structured text (ST) language, which one of the programming languages for IEC 61131-3. I hope that you find this description useful if you need to get started with the CAN interface.

Additional resources