Communication protocol conversion device and method based on embedded multiple MCU
Technical field
The present invention relates to a kind of communication Protocol Conversion technology, particularly relate to a kind of communication protocol conversion device and method based on embedded multiple MCU.
Background technology
At industry-by-industries such as electric power, oil, chemical industry, metallurgy, iron and steel, traffic, on-site signal need be sent to supervisory control systems such as upper DAS, DCS by data communication network after carrying out continuous acquisition and processing by data acquisition system.Because field level equipment exists many different with the equipment of controlled stage or monitoring level for data processing and transmission, therefore on-site signal is sent in the process of upper location supervisory often needs through different data communication networks, and communication protocol conversion device is just essential.
Fast development along with technology such as computer, electronics, automation, Networks and Communications, networking, intellectuality, digitized dcs have obtained extensive use, and this just requires the accuracy of the every data of control system and reliability are had higher requirement.And at present most of adopt not only disposal ability is limited based on the Single Chip Microcomputer (SCM) system of single task order mechanism, and have system real time, the relatively poor problem of reliability.In recent years, embedded technology has obtained developing rapidly, embedded system can adapt to the strict demand of data acquisition and monitoring system to aspects such as function, reliability, cost, volume and power consumptions well, is that the communication protocol conversion device that core makes up data acquisition of new generation and monitoring system has the important application meaning with high-performance embedded microprocessor.
Summary of the invention
It is limited to The present invention be directed in the existing communication technology Single Chip Microcomputer (SCM) system disposal ability, and there are system real time, the relatively poor problem of reliability, a kind of communication protocol conversion device and method based on embedded multiple MCU proposed, adopt embedded multiple MCU and high speed dual port RAM data sharing technology, improve reliability, the real-time of system, can conveniently realize exchanges data, data sharing and information processing between embedded MCU.
Technical scheme of the present invention is: a kind of communication protocol conversion device based on embedded multiple MCU, comprise the LCD liquid crystal display, button, Ethernet, the RSB485 communication interface, the RS232 communication interface, also comprise embedded from MCU, dual port RAM, embedded main MCU, wherein embeddedly realize and the industry spot data communication with Modbus/RTU or ASCII protocol by RS232 communication interface or RS485 communication interface from MCU, embeddedly data are put into the dual port RAM from MCU, embedded main MCU and dual port RAM swap data, receive the instruction of keyboard, and be in charge of system parameter setting, simultaneously data are outputed to the LCD liquid crystal display, and remote data is transferred to upper location supervisory by ethernet interface.
Described dual port RAM adopts the IDT7134 chip with asynchronous high-speed twoport static RAM (SRAM), and this chip has two fully independently ports, and each port all has control line, address wire and the data wire of oneself, race logic circuit that inside is integrated.The RAM memory of described IDT7134 chip is divided into two, passes to embedded data from MCU for embedded main MCU for one, this part only allows embedded main MCU read-write, and is embedded read-only from MCU; Another piece is embeddedly to pass to the data of embedded main MCU from MCU, and this part only allows embedded from the MCU read-write, and embedded main MCU is read-only.
A kind of communication protocol conversion method based on embedded multiple MCU comprises communication protocol conversion device and real-time multi-task operating system uC/OS-II based on embedded multiple MCU, and concrete grammar may further comprise the steps:
1) call OSInit () function: OSInit () function has been set up 2 tasks: idle task and statistics task, and wherein idle task is not moved when every other task is ready, and statistics task mainly calculates the utilance of CPU;
2) carry out InitHardware () function, finish system clock setting and each hardware parameter setting, carry out InitPara () function and finish the system global variables initialization, carry out the initialization that CommInit () function is finished UART serial ports parameter, set up communication task;
3) enter the uC/OS-II of system kernel, multitask brings into operation;
4) communication task of system is mainly finished request of data and is waited for the answer signal amount that receives interrupt service subroutine, finishes the function that sends the claim frame data in the idle task that the uC/OS-II kernel is set up;
5) system establishes 3 interrupt service subroutines: regularly interruption, outside 0 is interrupted and the communication reception is interrupted, wherein regularly interrupt realizing time-delay and overtime controlled function, outside 0 interrupts sending communication finishes semaphore functionality, and communication receives interrupts being responsible for receiving the acknowledgement frame data;
6) all reinitialize the UART serial ports one time after each communication is finished, can eliminate the accumulated error of communication baud rate, program can realize and 32 Slave device talks, sends Slave device address number successively.
Beneficial effect of the present invention is: the present invention is based on the communication protocol conversion method of embedded multiple MCU, realize the relaying and the protocol conversion function of industrial communication network, so that the serial equipment of mechanical floor can easily be connected to the supervisory layers network.Communication protocol conversion device adopts embedded multiple MCU and high speed dual port RAM data sharing technology, simplifies circuit design, improves reliability, the real-time of system, convenient exchanges data, data sharing and the information processing that realizes between embedded MCU.
Description of drawings
Fig. 1 the present invention is based on the system construction drawing of the communication protocol conversion device of embedded multiple MCU;
Fig. 2 the present invention is based on the communication protocol conversion method main program flow chart of embedded multiple MCU;
Fig. 3 the present invention is based on the communication protocol conversion method communication task scheduling process figure of embedded multiple MCU;
Fig. 4 the present invention is based on the communication protocol conversion method communication task program flow diagram of embedded multiple MCU;
Fig. 5 the present invention is based on the communication protocol conversion method data requester flow chart of embedded multiple MCU;
Fig. 6 the present invention is based on the communication protocol conversion method Data Receiving interrupt service routine flow chart of embedded multiple MCU.
Embodiment
As shown in Figure 1, the communication protocol conversion device based on embedded multiple MCU comprises embedded from MCU1, dual port RAM 2, LCD liquid crystal display 3, embedded main MCU4, button 5, Ethernet 6, RSB485 communication interface 7 and RS232 communication interface 8.Wherein embeddedly realize data acquisition I/O module with mechanical floor by RS232 communication interface 8 or RS485 communication interface 7 with agreements such as Modbus/RTU or ASCII from MCU1, the communication of intelligent instrumentation etc., obtain the industry spot measurement data, embeddedly data are put into the dual port RAM 2 from MCU1, embedded main MCU4 and dual port RAM 2 swap datas, receive the instruction of keyboard 5, and be in charge of system parameter setting, simultaneously data are outputed to LCD liquid crystal display 3, and pass through Ethernet 6 communication interfaces with Modbus/TCP, agreements such as TCP/IP are transferred to upper DAS with remote data, supervisory control systems such as DCS.
The present invention has adopted high speed dual port RAM data sharing technology, dual port RAM 2 chips adopt IDT7134, and this chip is an asynchronous high-speed twoport static RAM (SRAM), has two fully independently ports, each port all has control line, address wire and the data wire of oneself, race logic circuit that inside is integrated.Embedded MCU is equivalent to the operation of dual port RAM port its external RAM is operated.The present invention distributes memory according to the transfer of data characteristics, realizes arbitration on software, employing is divided into two with the RAM memory of IDT7134, pass to embedded data from MCU for embedded main MCU for one, this part only allows embedded main MCU read-write, and is embedded read-only from MCU; Another piece is embeddedly to pass to the data of embedded main MCU from MCU, and this part only allows embedded from the MCU read-write, and embedded main MCU is read-only.So just solved the problem of shared data conflict.In addition, the address latch of communication protocol conversion device adopts 74HC373 and 74HC573, is respectively applied for the address latch of the left and right sides port of dual port RAM.
Be illustrated in figure 2 as main program flow chart of the present invention, but its software platform adopts that source code is open, portable cutting, curable preemptive type real-time multi-task operating system uC/OS-II.Adopt the uC/OS-II The Realtime Operating System Nucleus, simplified the design of application system, make whole system simple for structure, make complicated application program levelization.Before any function of using uC/OS-II to provide, must call OSInit () function.OSInit () function has been set up 2 tasks: idle task and statistics task, and wherein idle task is not moved when every other task is ready, and statistics task mainly calculates the utilance of CPU.InitHardware () function is mainly finished system clock setting and each hardware parameter setting, and InitPara () function is finished the system global variables initialization, and CommInit () function is finished the initialization of UART serial ports parameter, sets up communication task.
Be illustrated in figure 3 as communication task scheduling process of the present invention, the communication task of system is responsible for the acknowledgement frame data of treatment S lave.Promptly finish request of data and wait for the answer signal amount that receives interrupt service subroutine, finish in the idle task of function by the foundation of uC/OS-II kernel of transmission claim frame data.There are 3 interrupt service subroutines in system: regularly interruption, outside 0 is interrupted and the communication reception is interrupted.Regularly interrupt realizing functions such as time-delay and overtime control, outside 0 interrupts sending communication finishes semaphore functionality, and communication receives interruption and is responsible for receiving the acknowledgement frame data.Communication dispatch moves on to idle task to the function that sends the claim frame data, and the communicating interrupt service subprogram is changed into non-shielding interruption, can not be subjected to the uC/OS-II inner core managing like this.But the service that can not use kernel to provide in the communicating interrupt service subprogram so promptly can not be called OSSemPost () function transmission communication and finished semaphore.In order to address this problem, increased outside 0 interrupt service subroutine, after promptly in the communicating interrupt service subprogram, receiving the complete answer frame data, trigger once outside 0 interruption (being subjected to the uC/OS-II inner core managing), externally call the transmission of OSSemPost () function in 0 interrupt service subroutine and receive the acknowledgement frame data semaphore.So both solve the response speed of communication, improved real-time and reliability again.
Be illustrated in figure 4 as communication task program flow diagram of the present invention, all reinitialize the UART serial ports one time after it should be noted that each communication, can eliminate the accumulated error of communication baud rate like this.Program can realize and 32 Slave device talks, sends Slave device address number successively.
Communication task is mainly finished request of data and is waited for the function of the answer signal amount that receives interrupt service subroutine.The data requester flow process as shown in Figure 5, Data Receiving interrupt service routine flow process is as shown in Figure 6.