CN106209678A - MODBUS message frame method of reseptance for DSP/BIOS - Google Patents
MODBUS message frame method of reseptance for DSP/BIOS Download PDFInfo
- Publication number
- CN106209678A CN106209678A CN201610513358.3A CN201610513358A CN106209678A CN 106209678 A CN106209678 A CN 106209678A CN 201610513358 A CN201610513358 A CN 201610513358A CN 106209678 A CN106209678 A CN 106209678A
- Authority
- CN
- China
- Prior art keywords
- message frame
- dsp
- interrupt thread
- clock
- modbus
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 37
- 238000012545 processing Methods 0.000 claims description 41
- 230000000737 periodic effect Effects 0.000 claims description 10
- 230000005540 biological transmission Effects 0.000 claims description 7
- 230000002093 peripheral effect Effects 0.000 abstract description 3
- 230000006854 communication Effects 0.000 description 10
- 238000004891 communication Methods 0.000 description 9
- 238000005516 engineering process Methods 0.000 description 2
- 238000011160 research Methods 0.000 description 2
- 239000003245 coal Substances 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005065 mining Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L49/00—Packet switching elements
- H04L49/90—Buffering arrangements
- H04L49/9063—Intermediate storage in different physical parts of a node or terminal
- H04L49/9068—Intermediate storage in different physical parts of a node or terminal in the network interface card
- H04L49/9073—Early interruption upon arrival of a fraction of a packet
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Synchronisation In Digital Transmission Systems (AREA)
Abstract
Description
技术领域technical field
本发明涉及MODBUS消息帧接收方法,具体涉及一种用于DSP/BIOS的MODBUS消息帧接收方法。The invention relates to a method for receiving a MODBUS message frame, in particular to a method for receiving a MODBUS message frame for DSP/BIOS.
背景技术Background technique
Modbus是由Modicon在1979年发明的全球第一个真正用于工业现场的总线协议,已经成为工业领域通信协议标准,也得到广泛应用。确定通讯线路的空闲时间并由此准确区分两消息帧,一直是MODBUS通讯过程必须解决的重要问题。现有技术中,微处理器和MODBUS设备的通讯全都采用定时器中断的方法来实现,即令定时器定时值等于消息帧帧间时间间距,在每次进入SCI中断程序时重置定时器的当前计时值,当进入定时器中断程序时,就说明当前消息帧已完成传输,此技术可见于《煤矿机械》2013年发表的《基于STM32F103和MODBUS的矿用DTU测试系统设计》、王谛的《基于MODBUS协议的PC机与dsPIC6014处理器的通讯》、《实验室研究与探索》2012年发表的《基于Modbus协议的S7-200系列PLC与单片机主从通信研究》等。这种方法虽然简单并容易实现,但占用了微处理器宝贵的定时器资源,使其硬件资源得不到有效利用,也提高了自动控制系统对微处理器的外设资源需求。Modbus, invented by Modicon in 1979, is the world's first real bus protocol for industrial field. It has become the communication protocol standard in the industrial field and has been widely used. Determining the idle time of the communication line and thus accurately distinguishing the two message frames has always been an important problem that must be solved in the MODBUS communication process. In the prior art, the communication between the microprocessor and the MODBUS equipment is all realized by the method of timer interruption, that is, the timer timing value is equal to the time interval between message frames, and the current value of the timer is reset when entering the SCI interrupt program each time. Timing value, when entering the timer interrupt program, it means that the current message frame has been transmitted. This technology can be seen in "Design of Mining DTU Test System Based on STM32F103 and MODBUS" published in "Coal Mining Machinery" in 2013, " Communication between PC and dsPIC6014 processor based on MODBUS protocol", "Research on master-slave communication between S7-200 series PLC and single-chip microcomputer based on Modbus protocol" published in "Laboratory Research and Exploration" in 2012, etc. Although this method is simple and easy to implement, it takes up valuable timer resources of the microprocessor, making its hardware resources not effectively utilized, and also increases the peripheral resource requirements of the automatic control system for the microprocessor.
发明内容Contents of the invention
为了解决上述现有的MODBUS通讯技术占用微处理器定时器资源的问题,本发明提供了一种用于DSP/BIOS的MODBUS消息帧接收方法。In order to solve the above-mentioned problem that the existing MODBUS communication technology occupies microprocessor timer resources, the present invention provides a MODBUS message frame receiving method for DSP/BIOS.
为实现上述目的,本发明采用下述技术方法:To achieve the above object, the present invention adopts the following technical methods:
一种用于DSP/BIOS的MODBUS消息帧接收方法,基于DSP/BIOS软件平台实现,包括消息帧接收流程和消息帧处理流程,所述消息帧接收流程选择SCI硬件中断线程实现,所述消息帧处理流程选择周期软中断线程实现。A kind of MODBUS message frame receiving method for DSP/BIOS, realizes based on DSP/BIOS software platform, comprises message frame receiving flow and message frame processing flow, described message frame receiving flow selects SCI hardware interrupt thread to realize, described message frame Processing flow selection cycle soft interrupt thread implementation.
进一步地,所述的SCI硬件中断线程具体运行过程为:Further, the specific running process of the SCI hardware interrupt thread is:
(1)串口接收到1字符数据后进入SCI硬件中断线程;(1) The serial port enters the SCI hardware interrupt thread after receiving 1 character data;
(2)重置消息帧处理周期软中断线程计时时钟;(2) Reset message frame processing cycle soft interrupt thread timing clock;
(3)读取接收到的数据,并保存到接收帧数组中当前成员号值指向的成员;(3) Read the received data and save it to the member pointed to by the current member number value in the received frame array;
(4)接收帧数组当前成员号加1;(4) Add 1 to the current member number of the receiving frame array;
(5)从SCI硬件中断线程返回;(5) Return from the SCI hardware interrupt thread;
进一步地,消息帧处理周期软中断线程计时时钟由系统时钟驱动。Further, the timing clock of the message frame processing cycle soft interrupt thread is driven by the system clock.
进一步地,消息帧处理周期软中断线程时钟周期为传输3.5字符数据所需的时间。Further, the message frame processing cycle soft interrupt thread clock cycle is the time required to transmit 3.5 character data.
进一步地,消息帧处理周期软中断线程采用单次运行模式。Furthermore, the message frame processing cycle soft interrupt thread adopts a single operation mode.
进一步地,所述的消息帧处理周期软中断线程具体运行过程为:Further, the specific running process of the soft interrupt thread of the message frame processing cycle is:
(1)消息帧处理周期软中断线程计时时钟值等于设定的时钟周期时进入运行;(1) When the soft interrupt thread timing clock value of the message frame processing cycle is equal to the set clock cycle, it enters into operation;
(2)接收帧数组当前成员号清零;(2) The current member number of the receiving frame array is cleared;
(3)数据处理;(3) data processing;
(4)发送应答消息帧;(4) Send a response message frame;
(5)从消息帧处理周期软中断线程返回。(5) Return from the message frame processing cycle soft interrupt thread.
与现有技术相比,本发明采用系统时钟取代现有技术中以定时器确定字符间隔时间并准确区分两消息帧的方法,可有效节省微处理器的硬件资源,降低自动化控制系统对微处理器的外设资源需求。Compared with the prior art, the present invention adopts the system clock to replace the prior art method of determining character interval time and accurately distinguishing two message frames by a timer, which can effectively save the hardware resources of the microprocessor and reduce the impact of the automatic control system on the microprocessor. The device's peripheral resource requirements.
附图说明Description of drawings
图1为本发明实施例的消息帧接收流程图;Fig. 1 is the message frame receiving flowchart of the embodiment of the present invention;
图2为本发明实施例的消息帧处理流程图;Fig. 2 is a message frame processing flowchart of an embodiment of the present invention;
图3为具体实施方式中TMS320F28335型DSP与MODBUS设备的连接图。Fig. 3 is the connection diagram of TMS320F28335 type DSP and MODBUS equipment in the specific embodiment.
具体实施方式detailed description
下面结合附图和实例对本发明进一步说明。The present invention will be further described below in conjunction with accompanying drawings and examples.
如图1和图2所示,一种用于DSP/BIOS的MODBUS消息帧接收方法,基于DSP/BIOS软件平台实现,包括消息帧接收流程和消息帧处理流程,所述消息帧接收流程选择SCI硬件中断线程实现,所述消息帧处理流程选择周期软中断线程实现。As shown in Fig. 1 and Fig. 2, a kind of MODBUS message frame receiving method for DSP/BIOS, realizes based on DSP/BIOS software platform, comprises message frame receiving flow and message frame processing flow, described message frame receiving flow selects SCI The hardware interrupt thread is implemented, and the message frame processing flow is implemented by a periodic soft interrupt thread.
具体而言,所述的SCI硬件中断线程具体运行过程为:Specifically, the specific running process of the SCI hardware interrupt thread is:
(1)串口接收到1字符数据后进入SCI硬件中断线程;(1) The serial port enters the SCI hardware interrupt thread after receiving 1 character data;
(2)重置消息帧处理周期软中断线程计时时钟;(2) Reset message frame processing cycle soft interrupt thread timing clock;
(3)读取接收到的数据,并保存到接收帧数组中当前成员号值指向的成员;(3) Read the received data and save it to the member pointed to by the current member number value in the received frame array;
(4)接收帧数组当前成员号加1;(4) Add 1 to the current member number of the receiving frame array;
(5)从SCI硬件中断线程返回。(5) Return from the SCI hardware interrupt thread.
具体而言,消息帧处理周期软中断线程计时时钟由系统时钟驱动。Specifically, the message frame processing cycle soft interrupt thread timing clock is driven by the system clock.
具体而言,消息帧处理周期软中断线程时钟周期为传输3.5字符数据所需的时间。Specifically, the message frame processing cycle soft interrupt thread clock cycle is the time required to transmit 3.5 character data.
具体而言,消息帧处理周期软中断线程采用单次运行模式。Specifically, the message frame processing cycle soft interrupt thread adopts a single-run mode.
具体而言,所述的消息帧处理周期软中断线程具体运行过程为:Specifically, the specific running process of the soft interrupt thread of the message frame processing cycle is:
(1)消息帧处理周期软中断线程计时时钟值等于设定的时钟周期时进入运行;(1) When the soft interrupt thread timing clock value of the message frame processing cycle is equal to the set clock cycle, it enters into operation;
(2)接收帧数组当前成员号清零;(2) The current member number of the receiving frame array is cleared;
(3)数据处理;(3) data processing;
(4)发送应答消息帧;(4) Send a response message frame;
(5)从消息帧处理周期软中断线程返回。(5) Return from the message frame processing cycle soft interrupt thread.
DSP是数字信号处理器的简称,本实例选用TI公司生产的C2000系列、型号为TMS320F28335的DSP处理器,TMS320F28335与MODBUS设备通过RS232连接(见图3),波特率选用9600b/s,通讯模式采用MODBUS RTU,数据传输格式为1bit起始位、8bit数据位、1bit停止位、无校验位。DSP is the abbreviation of digital signal processor. In this example, the DSP processor of C2000 series and model TMS320F28335 produced by TI company is selected. TMS320F28335 is connected with MODBUS equipment through RS232 (see Figure 3). The baud rate is 9600b/s, and the communication mode is Adopt MODBUS RTU, the data transmission format is 1bit start bit, 8bit data bit, 1bit stop bit, no parity bit.
DSP/BIOS是TI公司特别为其TMS320C6000TM,TMS320C5000TM和TMS320C28xTM系列DSP平台所设计开发的一个尺寸可裁剪的实时多任务操作系统内核。DSP支持四种不同优先级的线程,按照优先级从高到低顺序排列,分别是硬件中断(HWI)、软件中断(SWI)、任务(TSK)和后台线程(IDL)。周期函数(PRD)是一种特殊的软件中断,当其计时时钟等于设定的时钟周期值时进入就绪状态,其实例主要配置参数有:DSP/BIOS is a size-cuttable real-time multitasking operating system kernel specially designed and developed by TI for its TMS320C6000TM, TMS320C5000TM and TMS320C28xTM series DSP platforms. DSP supports four threads with different priorities, which are arranged in order of priority from high to low, namely hardware interrupt (HWI), software interrupt (SWI), task (TSK) and background thread (IDL). Periodic function (PRD) is a special software interrupt. When its timing clock is equal to the set clock period value, it enters the ready state. The main configuration parameters of its example are:
(1)period:周期函数时钟周期值,周期函数当前时钟计时值达到设定的时钟周期值时进入就绪状态,计时时钟可由系统时钟驱动,或调用PRD_tick函数后加1;(1) period: Periodic function clock period value. When the current clock timing value of the periodic function reaches the set clock period value, it enters the ready state. The timing clock can be driven by the system clock, or add 1 after calling the PRD_tick function;
(2)mode:周期函数运行模式,有连续运行(continuous)和单次触发(one-shot)两种。(2) mode: Periodic function operation mode, there are two types of continuous operation (continuous) and single-shot (one-shot).
本发明主要使用到的API函数及其功能如下:The API function and function thereof that the present invention mainly uses are as follows:
(1)PRD_start:用于启动一个周期函数的计时时钟,该周期函数在启动并等待设定的时钟周期后进入运行。如果在周期函数当前时钟计时值达到设定的时钟周期值前再次调用PRD_start,当前时钟计数值从零重新开始计时。(1) PRD_start: It is used to start a timing clock of a periodic function, and the periodic function enters operation after starting and waiting for the set clock cycle. If PRD_start is called again before the current clock count value of the periodic function reaches the set clock cycle value, the current clock count value will restart from zero.
在TMS320F28335的DSP/BIOS程序中,将消息帧接收流程创建为SCI硬件中断线程,消息帧处理流程创建为周期软中断线程。其中本发明的实现需要设置消息帧处理线程为单次触发模式,且其时钟周期值(period)设置为MODBUS通讯中两消息帧或数据包之间的最小时间间隔,即3.5字符数据传输时间,其计时时钟由系统时钟驱动。在波特率为9600b/s、传输格式为10bit,消息帧处理周期软中断线程时钟周期值如下:In the DSP/BIOS program of TMS320F28335, the message frame receiving process is created as an SCI hardware interrupt thread, and the message frame processing process is created as a periodic soft interrupt thread. Wherein the realization of the present invention needs to set the message frame processing thread as a single trigger mode, and its clock cycle value (period) is set to the minimum time interval between two message frames or data packets in the MODBUS communication, i.e. 3.5 character data transmission time, Its timing clock is driven by the system clock. When the baud rate is 9600b/s and the transmission format is 10bit, the message frame processing cycle soft interrupt thread clock cycle value is as follows:
当串口接收到MODBUS设备传输的1字符数据时,DSP/BIOS程序进入消息帧接收线程。在该线程中,首先调用PRD_start函数启动消息帧处理PRD线程的计时时钟,然后从SCI接收寄存器中读取数据并保存到接收帧数组,在令接收帧数组当前成员号加1后返回。在同一个数据包的传输过程中,DSP/BIOS程序不断重复以上过程。由于一个数据包中两字符数据传输间隔小于消息帧处理周期软中断线程的时钟周期值,并且每次进入SCI硬件中断线程时调用PRD_start复位消息帧处理周期软中断线程的当前计时时钟值,因此DSP/BIOS程序不会进入消息帧处理周期软中断线程。而当前消息帧传输完毕后,通讯线空闲时间大于消息帧处理周期软中断线程的时钟周期值,该线程在当前计时时钟达到时钟周期值后进入运行。When the serial port receives 1-character data transmitted by the MODBUS device, the DSP/BIOS program enters the message frame receiving thread. In this thread, first call the PRD_start function to start the timing clock of the message frame processing PRD thread, then read the data from the SCI receiving register and save it to the receiving frame array, and return after adding 1 to the current member number of the receiving frame array. During the transmission process of the same data packet, the DSP/BIOS program constantly repeats the above process. Since the two-character data transmission interval in a data packet is less than the clock cycle value of the message frame processing cycle soft interrupt thread, and calls PRD_start to reset the current timing clock value of the message frame processing cycle soft interrupt thread when entering the SCI hardware interrupt thread each time, the DSP The /BIOS program will not enter the message frame processing cycle soft interrupt thread. After the current message frame transmission is completed, the idle time of the communication line is greater than the clock cycle value of the message frame processing cycle soft interrupt thread, and the thread starts running after the current timing clock reaches the clock cycle value.
消息帧处理周期软中断线程负责处理接收到的消息帧。首先重置接收帧数组当前成员号,以接收下一消息帧。然后对消息帧进行处理,如CRC校验、提取消息帧数据域中的有效数据等。若TMS320F28335为MODBUS从机,根据对有效数据的解释发送相应的应答消息帧后从该线程返回;若为MODBUS主机,则直接返回。The message frame processing cycle soft interrupt thread is responsible for processing the received message frame. First reset the current member number of the receive frame array to receive the next message frame. Then process the message frame, such as CRC check, extract valid data in the data field of the message frame, and so on. If TMS320F28335 is a MODBUS slave, it will return from this thread after sending the corresponding response message frame according to the interpretation of valid data; if it is a MODBUS master, it will return directly.
本发明的上述实施例仅仅是为清楚地说明本发明所作的举例,而并非是对本发明的实施方式的限定。对于所属领域的普通技术人员来说,在上述说明的基础上还可以做出其它不同形式的变化或变动。这里无需也无法对所有的实施方式予以穷举。凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明权利要求的保护范围之内。The above-mentioned embodiments of the present invention are only examples for clearly illustrating the present invention, rather than limiting the implementation of the present invention. For those of ordinary skill in the art, other changes or changes in different forms can be made on the basis of the above description. It is not necessary and impossible to exhaustively list all the implementation manners here. All modifications, equivalent replacements and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the claims of the present invention.
Claims (6)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610513358.3A CN106209678A (en) | 2016-06-30 | 2016-06-30 | MODBUS message frame method of reseptance for DSP/BIOS |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610513358.3A CN106209678A (en) | 2016-06-30 | 2016-06-30 | MODBUS message frame method of reseptance for DSP/BIOS |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106209678A true CN106209678A (en) | 2016-12-07 |
Family
ID=57464301
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610513358.3A Pending CN106209678A (en) | 2016-06-30 | 2016-06-30 | MODBUS message frame method of reseptance for DSP/BIOS |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106209678A (en) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101035142A (en) * | 2006-03-07 | 2007-09-12 | 中国科学院声学研究所 | Ethernet interface realization method in the built-in system |
CN102025694A (en) * | 2009-09-11 | 2011-04-20 | 中兴通讯股份有限公司 | DSP (Digital Signal Processor) array based device and method for sending Ethernet data |
CN104065545A (en) * | 2014-06-27 | 2014-09-24 | 浙江大学 | RS485 bus communication method based on Modbus protocol and power electronic system based on the communication method |
-
2016
- 2016-06-30 CN CN201610513358.3A patent/CN106209678A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101035142A (en) * | 2006-03-07 | 2007-09-12 | 中国科学院声学研究所 | Ethernet interface realization method in the built-in system |
CN102025694A (en) * | 2009-09-11 | 2011-04-20 | 中兴通讯股份有限公司 | DSP (Digital Signal Processor) array based device and method for sending Ethernet data |
CN104065545A (en) * | 2014-06-27 | 2014-09-24 | 浙江大学 | RS485 bus communication method based on Modbus protocol and power electronic system based on the communication method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102043667A (en) | Task scheduling method for embedded operating system | |
CN102779075A (en) | Method, device and system for scheduling in multiprocessor nuclear system | |
CN111104272B (en) | CAN bus controller testing method based on RX and TX | |
CN103440216A (en) | Chip and method for debugging MCU through I2C slave unit | |
CN101883003A (en) | A computer operating system forced operation method | |
CN107423239B (en) | The complete data frame receiving method of low-power microcontroller in Halt mode | |
CN101561778B (en) | Method for detecting task closed loop of multi-task operating system | |
CN110519016B (en) | Three-in-one network data sending method based on real-time priority dynamic adjustment | |
CN105610915A (en) | Data reporting method and system | |
CN103197971B (en) | The implementation method of the low CPU usage intervalometer of high accuracy under Windows operating system Pentium IV framework | |
CN101924667A (en) | A serial port-based modem abnormal detection and power-off restart control method | |
CN101236541A (en) | Centralized control interrupt controller and its interrupt control method | |
CN112087052A (en) | An intelligent power distribution terminal | |
CN101094110A (en) | System and method for setting up, detecting and displaying interval time of characters inside Modbus RTU frame and between frames | |
CN102298095A (en) | Method for ensuring accurate measurement on pulse width in multi-task singlechip system and device | |
CN109189598A (en) | A kind of method, processor and terminal device interrupting positioning | |
CN106209678A (en) | MODBUS message frame method of reseptance for DSP/BIOS | |
CN112611083B (en) | Multi-split internal and external machine communication method and multi-split machine | |
CN104656604B (en) | A kind of utilization MODBUS communication protocols realize the safety and stability control device of electric network and its method of man-machine interaction | |
CN101873257B (en) | Method and system for receiving messages | |
CN102880576B (en) | Method for simulating multiple groups of UART interfaces based on STM32F103VE chip | |
CN104317717B (en) | Embedded software testing method on basis of dimension conversion | |
CN109062747B (en) | Intelligent testing method for digital satellite embedded simulation platform | |
CN102360343A (en) | Realization method of interrupt expansion of communication equipment | |
CN103970027A (en) | Telemetry processing unit simulation method in integrated electronic simulation software environment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20161207 |
|
RJ01 | Rejection of invention patent application after publication |