The Design of a DeviceNet – SPI Converter Module Based on the STM32 MCU

【来自IEEE,机器翻译未经授权。这篇好水,是本科生写的…】

Abstract –

According to the characteristics of the STM32 technology and DeviceNet fieldbus, this paper designs a DeviceNet – SPI converter module. The converter module solves the problem of conversion between the DeviceNet fieldbus and the SPI protocol, making the equipment with SPI interface have the communication function of DeviceNet fieldbus through the converter module, at the same time making up for the shortcomings of SPI protocol with no response mechanism. The converter module is introduced the design in detail from the hardware to software and the building of experimental platform to test the design of the system in this paper. Besides, the paper contains testing and verifying the feasibility and reliability of the converter module through the analysis of the results. Index Terms – STM32, DeviceNet, SPI, Converter module.

根据STM32技术和DeviceNet现场总线的特点,设计了DeviceNet-SPI转换器模块。 转换器模块解决了DeviceNet现场总线与SPI协议之间的转换问题,使具有SPI接口的设备通过转换器模块具有DeviceNet现场总线的通讯功能,同时弥补了SPI协议无响应的缺点。 机制。 从硬件到软件详细介绍了转换器模块的设计,并通过实验平台的构建来测试系统的设计。 此外,本文还通过对结果的分析来测试和验证转换器模块的可行性和可靠性。 索引词-STM32,DeviceNet,SPI,转换器模块。

I. INTRODUCTION

SPI interface which is the full-duplex and three lines synchronous serial peripheral interface was firstly presented by the Motorola. It adopts the model of master-slave architecture and supports multiple slave devices and usually only single master. The clock is controlled by a master device. Data transmits according to the bit under the clock pulse. The rate of communication is up to 10 Mbps [1]-[5]. The SPI protocol has been widely used for its simple interface, convenience to the hardware design and implementation, high speed of clock and less system cost. But SPI has serious shortcomings.

SPI接口是全双工和三线同步串行外围设备接口,由Motorola首次提出。 它采用主从架构模型,并支持多个从设备,通常仅支持一个主设备。 时钟由主设备控制。 数据根据时钟脉冲下的位进行传输。 通信速率最高为10 Mbps [1]-[5]。 SPI协议以其简单的接口,方便的硬件设计和实现,高速的时钟以及更少的系统成本而被广泛使用。 但是SPI有严重的缺点。

First of all, it has no appointed flowing control, so that there is no response to confirm whether it has received the data; Secondly, it has no the mainly device protocol, therefore the complicated software and external logic must be used to realize the main component architecture [6]-[7]. DeviceNet is a high-level industrial field bus communication protocol based on CAN bus. In 1994, it was initially proposed by the United States Rockwell Automation company, managed and popularized by ODVA organization [8]-[11]. DeviceNet Bus is a kind of device-level fieldbus with low cost, good stability and high flexibility. It provides the network communication connection to the simple industrial equipment and advanced equipment reliably. It has been widely used in the field of global automation control, and gradually becomes the mainstream of industrial network communications.

首先,它没有指定的流控制,因此没有响应来确认它是否已接收到数据。 其次,它没有主要的设备协议,因此必须使用复杂的软件和外部逻辑来实现主要组件架构[6]-[7]。 DeviceNet是基于CAN总线的高级工业现场总线通信协议。 1994年,它最初由美国罗克韦尔自动化公司提出,由ODVA组织管理和推广[8]-[11]。 DeviceNet总线是一种成本低,稳定性好,灵活性高的设备级现场总线。 它可靠地提供了到简单工业设备和先进设备的网络通信连接。 它已被广泛用于全球自动化控制领域,并逐渐成为工业网络通信的主流。

DeviceNet is the high-level protocol based on CAN protocol, and its underlying uses the provisions of CAN bus protocol. DeviceNet is replenished and developed on this basis. The DeviceNet bus applies IO data communication mode is based on “producers – consumers” and explicit data communication mode is based on explicit connection [12]- [13]. A message transmits in the network by the form of radio, and each node can decide whether to receive message or not. The master station of DeviceNet is responsible for supervising and monitoring the running status of each node which is connected with it.

DeviceNet是基于CAN协议的高级协议,其底层使用了CAN总线协议的规定。 DeviceNet在此基础上进行补充和开发。 DeviceNet总线应用基于“生产者-消费者”的IO数据通信模式,而显式数据通信模式则基于显式连接[12]-[13]。 消息以无线电的形式在网络中传输,并且每个节点都可以决定是否接收消息。 DeviceNet的主站负责监督和监视与其连接的每个节点的运行状态。

The communication characteristics are the following: firstly, the typical way of request/response adopts for multipurpose point-to-point message transmission between two devices; Secondly, the protocol based on the conception of connection demanding its connection to the equipment before exchanging information between them; Thirdly, the physical signal and MAC layer use CAN protocol; Fourthly, the I/O data transmits efficiently and so on [14]-[15].

通信特性如下:首先,典型的请求/响应方式是在两个设备之间进行多用途的点对点消息传输。 其次,基于连接概念的协议要求它们在设备之间交换信息之前先连接到设备。 第三,物理信号和MAC层使用CAN协议。 第四,I / O数据有效传输,以此类推[14]-[15]。

The STM32F103xx performance line family incorporates the high-performance ARM Cortex-M3 32-bit RISC core operating at a 72 MHz frequency, high-speed embedded memories (Flash memory up to 128Kbytes and SRAM up to 20 Kbytes), and has an extensive range of enhanced I/Os and peripherals connected to two APB buses. All devices offer two 12-bit ADCs, three general purpose 16-bit timers plus one PWM timer, as well as standard and advanced communication interfaces: up to two I2Cs and SPIs, three USARTs, an USB and a CAN [16]-[19]. So the purpose of this article is to design a protocol converter module which combines the advantages of SPI and DeviceNet. 、

STM32F103xx性能线系列集成了以72 MHz频率运行的高性能ARM Cortex-M3 32位RISC内核,高速嵌入式存储器(闪存存储器高达128 KB,SRAM存储器高达20 KB),并且具有广泛的应用范围 连接到两条APB总线的增强型I / O和外围设备。 所有器件都提供两个12位ADC,三个通用16位定时器以及一个PWM定时器,以及标准和高级通信接口:最多两个I2C和SPI,三个USART,一个USB和一个CAN [16]-[ 19]。 因此,本文的目的是设计一种结合SPI和DeviceNet优点的协议转换器模块。

The module can make the equipment with SPI interface has the communication function of DeviceNet fieldbus. At the same time, it makes up for the shortcomings of SPI protocol with no response mechanism. This converter module employs the STM32F103C8T6 single chip microcomputer of the company of ST Microelectronics as the core processor. The single-chip microcomputer has a CAN controller, a SPI interface and other hardware resources. These resources are indispensable hardware to realize the transformation module, and greatly reduce the complexity of hardware design and development cost.

该模块可以使具有SPI接口的设备具有DeviceNet现场总线的通信功能。 同时,它弥补了没有响应机制的SPI协议的缺点。 该转换器模块采用ST Microelectronics公司的STM32F103C8T6单片机作为核心处理器。 单片机具有CAN控制器,SPI接口和其他硬件资源。 这些资源是实现转换模块必不可少的硬件,并大大降低了硬件设计和开发成本的复杂性。

II. HARDWARE DESIGN OF CONVERTER MODULE

This converter module consists of five parts: the core control chip STM32F103C8T6, CAN drive circuit, power conversion circuit, status indication circuit and SPI interface. The overall hardware structure is shown in figure 1.

该转换器模块由五部分组成:核心控制芯片STM32F103C8T6,CAN驱动电路,电源转换电路,状态指示电路和SPI接口。 整体硬件结构如图1所示。

Core control chip chooses STM32F103C8T6 microcontroller, which is produced by ST company and integrates the CAN protocol controller. Its function is connecting to the CAN transceiver to make up for CAN drive circuit to receive DeviceNet bus data. It converts the data received by single chip from CAN drive circuit to another data conforming to the SPI protocol, and then it sends the data to the SPI equipment or instrument by the SPI interface of the single chip microcomputer, so as to realize the conversion from DeviceNet fieldbus network to the SPI protocol; At the same time, the data of field equipment or instrument can be read through the SPI interface on MCU, and MCU converts the data to another data conform to the DeviceNet fieldbus protocol data; finally sending the data to the fieldbus network through the drive circuit, so as to realize the transformation from SPI protocol to the DeviceNet field bus network. The minimum system of MCU is shown in figure 2.

核心控制芯片选用由ST公司生产并集成CAN协议控制器的STM32F103C8T6微控制器。 它的功能是连接到CAN收发器,以弥补CAN驱动电路接收DeviceNet总线数据的不足。 它将单片机从CAN驱动电路接收到的数据转换为符合SPI协议的另一数据,然后通过单片机的SPI接口将数据发送到SPI设备或仪器,从而实现从SPI的转换。 DeviceNet现场总线网络到SPI协议; 同时,可以通过MCU上的SPI接口读取现场设备或仪器的数据,MCU将数据转换为符合DeviceNet现场总线协议数据的其他数据; 最后通过驱动电路将数据发送到现场总线网络,以实现从SPI协议到DeviceNet现场总线网络的转换。 MCU的最小系统如图2所示。

The circuit of CAN bus driver consists of CAN controller embedded in single chip microcomputer STM32F103C8T6 and CAN transceiver CTM1050T. The STM32F103C8T6 internal integrated CAN controller is mainly responsible for receiving and sending the CAN bus message, filtering packets and processing the mistakes of the bus communication. Due to the CAN controller is only a protocol controller inside the microcomputer and it can’t provide the physical layer driver, it is necessary to use external CAN bus transceiver capability to enhance bus driver when it is applied. This article chooses the chip CTM1050T as the CAN bus transceiver which has the segregation function and ESD protection function at the same time.

CAN总线驱动器电路由嵌入在单片机STM32F103C8T6中的CAN控制器和CAN收发器CTM1050T组成。 STM32F103C8T6内部集成CAN控制器主要负责接收和发送CAN总线消息,过滤数据包以及处理总线通信的错误。 由于CAN控制器仅是微型计算机内部的协议控制器,并且不能提供物理层驱动程序,因此应用时必须使用外部CAN总线收发器功能来增强总线驱动程序。 本文选择芯片CTM1050T作为同时具有隔离功能和ESD保护功能的CAN总线收发器。

The circuit of CAN bus driver is shown in figure 3. CTM1050T uses the supply of 5V power, so its two ports –the TXD and the RXD are the level of TTL5V. And the controller terminals of single chip microcomputer which are used to connect CTM1050T with CAN_TXD and CAN_RXD that have the feature of 3.3 V level. The both levels are compatible, but the ability of pins support level of microcontroller should be considered. MCU– STM32F103C8T6 has some IO pins for compatibility with TTL level, so that pins can bear 5 V. But the controller terminals of single microcomputer that are used can withstand without having to make changes. The circuit of filter is composed of R8 and C20. The both ends are respectively connecting CTM1050T terminal –CANG and Bus terminal– CANF. The circuit filtering is plenty useful. It plays an important role to increase the stability of the transceiver. R9 and S3 is forming the circuit of selection. If the converter module has been seen the terminal of equipment, then they will be selected to jumper in CANH and CANL.

CAN总线驱动器电路由嵌入在单片机STM32F103C8T6中的CAN控制器和CAN收发器CTM1050T组成。 STM32F103C8T6内部集成CAN控制器主要负责接收和发送CAN总线消息,过滤数据包以及处理总线通信的错误。 由于CAN控制器仅是微型计算机内部的协议控制器,并且不能提供物理层驱动程序,因此应用时必须使用外部CAN总线收发器功能来增强总线驱动程序。 本文选择芯片CTM1050T作为同时具有隔离功能和ESD保护功能的CAN总线收发器。

The circuit of the power conversion and status display consist of the two-stage step-down power circuit and the circuit of two LEDs. The working voltage of conversion module is 24 V and supplied by the DeviceNet bus interface. Because of the working voltage of single-chip microcomputer STM32F103C8T6 is 3.3 V and the working voltage of CTM1050T is 5 V, there should be not only the 5 V power supply the system but also the 3.3 V power supply system. The circuit of the power conversion adopts a two-stage stepdown method. First of all, the power can be exchanged from 24V into 5 V using LM2874M5 chip, and then the power can be step-down from 5V into 3.3 V using AM1117 3.3 chip. This is also helpful to increase the cooling volume. The circuit of status display is composed of two LEDs, which is denoting a state of microcontroller running and network communication respectively. The circuit of the power conversion is shown in figure 4.

电源转换和状态显示电路由两级降压电源电路和两个LED电路组成。 转换模块的工作电压为24 V,由DeviceNet总线接口提供。 由于单片机STM32F103C8T6的工作电压为3.3 V,而CTM1050T的工作电压为5 V,因此不仅应为系统提供5 V电源,而且还应具有3.3 V电源系统。 功率转换电路采用两级降压方法。 首先,可以使用LM2874M5芯片将电源从24V转换为5V,然后使用AM1117 3.3芯片将电源从5V转换为3.3V。 这也有助于增加冷却量。 状态显示电路由两个LED组成,分别表示微控制器正在运行和网络通信的状态。 功率转换电路如图4所示。

III. SOFTWARE DESIGN OF CONVERTER MODULE

The converter module is to complete the conversion between DeviceNet fieldbus and SPI protocol. After the system is powered on, firstly MCU should be initialized on clock, GPIO, SPI interface, etc. The SPI interface is configured as the slave equipment here. Then the time of system delays 300ms for reading the parameters of SPI master device into single chip microcomputer. After this work is done, the MCU runs DeviceNet protocol stack finally. System of the main program flow chart is shown in figure 5.

转换器模块将完成DeviceNet现场总线和SPI协议之间的转换。 系统上电后,首先应在时钟,GPIO,SPI接口等上初始化MCU。此处将SPI接口配置为从设备。 然后系统时间延迟了300ms,以便将SPI主设备的参数读入单片机。 完成此工作后,MCU最终运行DeviceNet协议栈。 主程序流程图系统如图5所示。

After the MCU is initialized, the main program of converter module must firstly complete the initialization of SPI driver. This initialization includes MCU’s GPIO port, SPI interface model and phase selection. This work for preparations is completed. Then MCU open the interrupt of SPI, and finally reset the data in the parameter list of equipment. The flow chart is shown in figure 6.

MCU初始化后,转换器模块的主程序必须首先完成SPI驱动程序的初始化。 初始化包括MCU的GPIO端口,SPI接口模型和相位选择。 准备工作已完成。 然后,MCU打开SPI的中断,最后将设备参数列表中的数据复位。 流程图如图6所示。

Running the DeviceNet protocol stack consists of: finishing CAN drive initialization, initializing the DeviceNet object, connecting object and initializing parameter object. After that, the system sends two duplicate detection MAC ID messages. If there are no errors, equipment is on-line and enters into a state of I/O data exchanging. The flow chart of DeviceNet protocol is shown in figure 7.

运行DeviceNet协议栈包括:完成CAN驱动器初始化,初始化DeviceNet对象,连接对象和初始化参数对象。 之后,系统会发送两个重复的检测MAC ID消息。 如果没有错误,则表明设备已联机并进入I / O数据交换状态。 DeviceNet协议的流程图如图7所示。

IV. TESTING

In order to verify the feasibility and reliability of the converter module, this paper designs the test platform. The structure chart of the test platform is shown in figure 8. The PC equipped with DeviceNet scan card—-1770 – KFD is responsible for running the program code to control the behaviour of the converter module. The testing steps are as follows: first of all, the EDS files of DeviceNet interface must be written, by using the AB Company Micrologix1500PLC and 1769 – SDN scanning module as the DeviceNet master station. Bus analyzer CANalyst – II as a DeviceNet network monitoring device, and then the DeviceNet interface of converter module connects to the DeviceNet bus. Finally the soft starter with SPI communication interface access to the SPI interface of converter module. After the testing platform is completed, it can complete the test of the function of the converter module through the experiment of controlling soft starter start-stop.

为了验证转换器模块的可行性和可靠性,本文设计了测试平台。 测试平台的结构图如图8所示。配备DeviceNet扫描卡的PC —- 1770-KFD负责运行程序代码以控制转换器模块的行为。 测试步骤如下:首先,必须使用AB公司Micrologix1500PLC和1769-SDN扫描模块作为DeviceNet主站来编写DeviceNet接口的EDS文件。 总线分析仪CANalyst-II作为DeviceNet网络监视设备,然后转换器模块的DeviceNet接口连接到DeviceNet总线。 最后,带有SPI通信接口的软启动器访问转换器模块的SPI接口。 测试平台完成后,可以通过控制软起动器的启停实验来完成对变频器模块功能的测试。

In this network, the master station sends four bytes to the network. The bytes are used to control the soft starter start and stop. The four bytes consist of two low bytes as a control word and two high bytes as a reserved word. The converter module returns four bytes to the master station, which is used to reflect the current state of the soft starter. These four bytes are composed of two low bytes as status words and two high bytes as a reserved word [20]. Test results are shown in figure 9 and 10

在此网络中,主站向网络发送四个字节。 这些字节用于控制软起动器的启动和停止。 这四个字节由两个低字节作为控制字和两个高字节作为保留字组成。 转换器模块将四个字节返回到主站,该主站用于反映软启动器的当前状态。 这四个字节由作为状态字的两个低字节和作为保留字的两个高字节组成[20]。 测试结果如图9和10所示

SUMMARY

This paper designs a DeviceNet-SPI converter module, which offers a good solution to solve the problem of conversion between the DeviceNet fieldbus and the SPI protocol .The system chooses the microelectronics STM32F103C8T6 MCU and greatly reduces the complexity and development cost of the system’s hardware design. This MCU integrates the CAN protocol controller and it is also has the low power consumption, the small size, the powerful functions and the fast processing speed. Experimental results show that this converter module can effectively transform the DeviceNet fieldbus to the SPI protocol, by using the converter module it can make the equipment originally only with SPI communication mode have the function of DeviceNet fieldbus communication, and it makes up for the shortcomings of SPI protocol– no response mechanism. It also provides a reference for fieldbus converter module of other products.

本文设计了一种DeviceNet-SPI转换器模块,为解决DeviceNet现场总线与SPI协议之间的转换问题提供了一个很好的解决方案。系统选择了微电子STM32F103C8T6 MCU,大大降低了系统硬件设计的复杂度和开发成本 。 该MCU集成了CAN协议控制器,具有功耗低,体积小,功能强大,处理速度快的特点。 实验结果表明,该转换器模块可以有效地将DeviceNet现场总线转换为SPI协议,通过使用该转换器模块,可以使原来只有SPI通讯模式的设备具有DeviceNet现场总线通讯的功能,弥补了该缺点。 SPI协议-无响应机制 它还为其他产品的现场总线转换器模块提供了参考。

Leave a Reply