1 Introduction
Modern remote measurement and control tasks require remote monitoring, control and remote data transmission of various industrial systems. Traditional centralized measurement and control systems can no longer meet the needs of complex, remote (off-site) and large-scale distributed measurement and control tasks. Moreover, most of
the
industrial control
and
communication
equipment use serial port devices that comply with the RS232 standard. As Internet technology is popularized in various fields around the world, how to forward serial port data to
the network
to achieve remote control of equipment and remote data transmission has become an urgent problem to be solved. At the same time, considering the cost issue, it is impossible to completely eliminate the previous equipment. Therefore, this paper proposes a TCP/IP-based serial port conversion gateway solution.
The serial port conversion gateway makes it possible to transmit serial port data streams to
Ethernet
data streams. It can connect to RS232 serial port devices, select and process serial port data, and convert the data stream of the RS232
interface
into Ethernet data streams, so that networked data processing can be performed to achieve networking of serial data. With this solution, there is no need to eliminate the original serial port equipment. Multiple devices can be connected to the network at the same time, which can not only improve the utilization rate of equipment, but also save networking costs and simplify the wiring complexity based on the existing network.
2 Hardware structure
The hardware platform is composed
of
STC
89C58
single-chip microcomputer
and RTL8019-AS Ethernet
controller.
The driver
of the network device is written
to realize the Ethernet communication function. The hardware structure of the system is shown in Figure 1. The system module can meet the remote monitoring work requirements of electrical equipment with RS-232 interface. It is a practical
network communication
module. The module uses the network interface chip RTL8019AS to enable the measurement and control equipment to access
the local area network
in a low-cost and simple way
. The main performance of the network interface chip RTL8019AS meets the Ethernet II and
IEEE
802.3 standards, full-duplex, and the transmission and reception can reach a rate of 10MB/s at the same time. The remote PC sends data to the Ethernet interface, the Ethernet interface stores the data in RAM, the on-site serial port device communicates with the microcontroller, and takes out data from RAM as the control command of the on-site equipment, thereby changing the working status of the on-site equipment.
Figure 1 System structure diagram
There are two RAM areas inside the rtl8019as, one is 32 bytes, the address is 0x0000-0x0001f, which is used to store the Ethernet physical address. The address of a 16k RAM is 0x4000-ox7fff. To receive and send data packets, this RAM must be read and written through DMA. The rtl8019as can be divided into remote DMA interface, local DMA interface,
MAC
logic, data encoding and decoding logic and other ports. The rtl8019as has 32-bit input and output addresses. The remote DMA address offset 0x10h-0x17h can be used as a remote DMA port. Just use one of them, and 0x10h is generally used. Remote DMA is the CPU reading data from the RAM of the network card to the system RAM, or sending data to the RAM of the network card. Local DMA is the network card receiving data uploaded from the Ethernet, or sending data in the network card RAM to the Ethernet (the network card automatically completes after the startup command).
The local DMA completes the data exchange between the control line and the network cable, and the processor CPU only needs to operate the remote DMA to send and receive data. When the processor wants to send data to the network, it first sends a frame of data to the send buffer in the rtl8019as through the remote DMA channel, and then issues a transmission command. After the rtl-8019as completes the transmission of the previous frame, it starts to send this frame. The data received by the rtl8019as is compared with the mac address and the crc check, and then stored in the receive buffer by the fifo. After receiving a full frame, the main processor is notified by interrupt or query register flag.
3 Software Design
3.1 Rtl8019as Initialization
When using rtl8019as as a network management chip, 8019 must be initialized
{page_select(0);
cr=0x4c;
pstart=0x80;
bnry=0x4c;
tpsr=0x40; //tpsr, send start page register
isr=0xff; //clear all interrupt flags
rcr=0xe0; //rcr, monitor mode, do not receive data packets
tcr=0xe2; //tcr, look back mode
dcr=0xc8; //data configuration register
imr=0x00; //interrupt flag mask register clear 0
page_select(1);
curr=0x4d;
cr=0x22; //start rtl8019as to start working
page_select(0);
cr=0x22; //start rtl8019as to start working
isr=0xff; //clear all interrupt flags
rcr=0xcc; //write the physical address of rtl8019as to the mar register
tcr=0xe0;
}
[page]
3.2 Data Encapsulation
To transmit data in the Ethernet, the serial port data must be encapsulated according to the Ethernet frame format, which is a layer-by-layer encapsulation process. The application adds the appl header to the device data to form the application data, and the TCP protocol adds the TCP header to the application data, encapsulating the data layer by layer. Finally, the rtl8019as chip adds the Ethernet header to the data. The encapsulation process is shown in Figure 2.
Figure 2 Schematic diagram of data encapsulation
The format of the encapsulated data transmission is as follows:
(1) Preamble: Generated by the RTL8019AS chip itself, used to synchronize
the clocks
of the two parties
and specify the transmission rate.
(2) Destination address DA: The destination address of the Ethernet data frame transmission, which is a 48-bit binary address. When all 1s are set, it indicates a broadcast address.
(3) Source address SA: The 48-bit source address of the Ethernet data frame transmission, indicating the starting point of the frame data, that is, the address of the sender.
(4) Frame format type: The type field indicates the type of the frame data. For example, the data type of the IP packet is 0800h, and the data type of the ARP packet is 0806h.
(5) Data: Ethernet stipulates that the maximum length of the entire data packet is 1514 bytes, and here it is stipulated that the data field cannot exceed 1500 bytes.
(6) CRC and padding: Ethernet stipulates that the entire data packet must be greater than 60 bytes. If it does not meet 60 bytes, any data will not make up 60 bytes.
3.3 Data processing framework
The data information from the client reaches the microcontroller through the RJ-45 Ethernet interface and the network interface chip. The microcontroller implements the address resolution protocol (ARP), Internet control message protocol (ICMP
)
, IP protocol and user datagram protocol (UDP) through the embedded TCP/IP protocol stack, thereby completing the parsing and unpacking of network data. The following program framework is used when programming network data processing:
{ if(Ethernet header frame type==0x0806)
{arp handler}
if(Ethernet header frame type==0x0835)
{parp handler}
if(Ethernet header frame type==0x0800)
{ip handler}
}
In normal operation, the task of the TCP/IP protocol conversion module is mainly to encapsulate the serial frame of the Ethernet send buffer in the UDP packet and pass it to the IP layer; at the same time, it receives the Ethernet data frame and unpacks it to the upper layer, separates the application layer data, and then the data parsing and processing are handed over to the multi-serial port sending module. After receiving the serial data, the microcontroller encapsulates it and writes it into the Ethernet send buffer for packaging and transmission; at the same time, it receives the data of the Ethernet application layer, parses it and sends it from the serial port. For this design, the specific form of the communication data is not important. Its main task is to receive/send, encapsulate/unpack serial frames, and provide a general gateway interface for serial devices.
4 Conclusion
This article introduces the gateway-to-serial communication based on TCP/IP, and uses the RTL8019AS chip to realize the online communication of serial devices. It is well adapted to low-speed, serial port industrial occasions. It builds a bridge between serial port electrical equipment and the network, realizes serial port equipment and monitoring and transparent data transmission, as well as network control of equipment and distributed management of information. It can be widely used in distributed measurement and control networks based on Ethernet. Through it, we can realize remote monitoring of various real-time signals,
instruments
, civil facilities and other targets, and unified management of various equipment. This will greatly improve work efficiency, improve the working environment, and enhance people's production and living standards.
Previous article:MCU music player C language program
Next article:Realizing fireworks function with dot matrix screen based on MCS-51 single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 20:23
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Differences between power meter and spectrum analyzer in measuring power
- [TI mmWave Radar Review] IWR1443 BOOST CLI Commands
- Selection and comparison of reed switches and Hall effect sensors
- [Project source code] [Modelsim FAQ] vsim-3033 Instantiation of 'xxxx' failed
- micropython update: 2020.12
- [Sipeed LicheeRV 86 Panel Review] The board is not responding
- Use stm32l452 to drive hts221 and stts751 routine
- [National Technology N32WB452 Review] + Basic Function Usage
- Will demand for SiC FETs increase in the future?
- Problems with pressure maintenance of testing machine