introduction
At present, automated monitoring devices such as coal mine gas, negative pressure, motors, and power supply have been widely used in major mines, and have even been networked and operated in individual mines. However, most of the automated monitoring devices still use RS232, RS485 or CAN bus networking, which seriously affects the real-time, reliability, and interactivity of the mine safety monitoring system. Industrial Ethernet has developed from 10 M and 100 M bandwidth to the current Gigabit network, and has become the main networking method for mine monitoring systems.
Therefore, how to make existing serial devices based on RS232, RS485 or CAN bus operate in an Ethernet network is a problem that currently needs to be solved. This article introduces a serial port server system based on S3C44B0. This server system can convert serial port data into TCP/IP protocol for data transmission, and has a wide range of application prospects.
1. System hardware structure
The hardware structure of the serial port server system based on S3C44B0 is shown in Figure 1.
Figure 1 Serial port server system hardware structure diagram based on S3C44B0
The main functions of the system: read data from the serial device, encapsulate the obtained data with TCP/IP protocol, send it to the host computer through the RJ 45 interface, and interact with the server program of the host computer; at the same time, send the host computer to The data from the serial server is forwarded to the serial port, and then the serial device on site can be remotely monitored through the network.
The RS232 interface circuit is shown in Figure 2. In this system, 2 independent serial ports are expanded, which can communicate with three-wire or Modem. This interface uses two MAX3232C chips, of which MAX3232C (1) is responsible for the level conversion of the serial port sending and receiving signals, and MAX3232C (2) completes the level conversion of the handshake signal. C10~C15 of processor S3C44B0 are used as nRTS1, nCTS1, TXD1, RXD1, nRTS0, nCTS0 signals respectively, and PE1 and PE2 are used as TXD0 and RXD0 signals.
Figure 2 RS232 interface circuit diagram
The Ethernet controller uses the network control chip RTL8019AS, which is widely used in the embedded field and has high cost performance. Its interface circuit is shown in Figure 3.
Figure 3 Ethernet controller interface circuit diagram
In Figure 3, RTL8019AS uses the IN T0 interrupt mode and is connected to the external interrupt pin IN T1 of the S3C44B0. The data bus width is 16 bits, therefore, pin IOCS16B of RTL8019AS is pulled up.
RTL8019AS has 3 working modes: jumper mode, in which I/O and interrupts are determined by jumpers; plug-and-play mode (PnP), which is automatically configured by software; jumper-free mode, in which I/O and interrupts are determined by the contents of the external EEPROM93C46.
Which working mode is used is determined by the pin JP of RTL8019AS. In Figure 3, the pin JP is pulled up, that is, the jumper mode is selected.
The pin IOS2 of RTL8019AS is pulled up, and the pins IOS0, IOS1, and IOS3 are floating (pins IOS0~IOS4 are not shown in Figure 3). When the pins IOS0, IOS1, and IOS3 are floating, there is 1 in each pin. 100 kΩ pull-down resistor, therefore, pins IOS0, IOS1, and IOS3 are low level, and the I/O base address of RTL8019AS is 200H.
The chip select terminal AEN of RTL8019AS is connected to nGCS5 of S3C44B0, which is Bank6. Since the data bus width is 16 bits, pin A1 of S3C44B0 is connected to pin SA0 of RTL8019AS. Therefore, for S3C44B0, the I/O base address of RTL8019AS is 0X0A000400H. 20F001N is a network card filter, which contains a pair of low-pass filters and a pair of isolation transformers, and is directly connected to the RJ 45.
2. System software structure
The system software is based on the uClinux operating system with Linux 2.4 kernel and adopts modular design. Its structural components are shown in Figure 4. The core of the system software is the serial port and Ethernet processing modules. The serial port server can realize the networking of serial port devices through these two modules.
Figure 4 System software structure module diagram
Since the uClinux kernel contains universal drivers for serial ports and network ports, there is no need to write serial port and network drivers. You only need to cut and transplant uClinux according to the hardware circuit during kernel transplantation, and then you can realize the serial port and network drivers. application programming capabilities.
The device management of uClinux is closely integrated with the file system. Various devices are stored in the /dev directory in the form of files, called device files. Applications can open, close, read and write these device files, and complete operations on the device just like operating ordinary data files. So to access the serial port, you only need to open the corresponding device file. Under uClinux, the devices corresponding to the serial ports COM1 and COM2 are /dev/ttyS0 and dev/ttyS1 respectively. The steps for programming the serial port are as follows:
(1) Open the serial port, use the open () function fd = open ("/dev/t tyS0", O_RDWR | O_NOCTTY); (2) If the opening is successful, set the parameters of the serial port:
tcgetat tr (fd, &oldtio); (3) Clear the serial port buffer, because the serial port receives and sends data starting from the buffer after the previous set of data. In order to prevent the previous data from recurring, the buffer is cleared. tcflush (fd, TCIFLUSH); (4) Read and write the serial port. The read (fd, sbuf, BU F_L EN) function is used to read the serial port. The write (fd, sbuf, BU F_L EN) function is used to write the serial port, where fd is the function returned by opening the device. value, sbuf is the data group that stores the sent or received data, BU F_ L EN is the number of data; (5) After the reading and writing is completed, close the serial port, close (fd).
The essence of network communication is communication between processes. Only when the network address and port number are combined can a network process in the entire Internet be determined. The network process is determined by a socket, and the program is represented by a Socket. There are two most commonly used types of sockets: Stream Socket and Datagram Socket. The difference between these 2 sockets is that they use different protocols. Streaming sockets use the TCP protocol, and datagram sockets use the UDP protocol. The protocol used in this system is TCP protocol. The specific communication steps are as follows:
(1) Create a listening socket by the socket() function;
(2) Assign an address to the socket through the bind () function;
(3) Use the listen () function to establish a connection with the client and tell the socket to start listening for the client’s connection request;
(4) The accept () function completes the actual connection and creates a connection socket. The original listening socket will continue to listen for new connection requests, and the new connection request may be passed through the accept () function again. Accepted in one call;
(5) After the connection socket is successfully created, the task of sending and receiving data can be completed. Data reception is completed by the recv () function, and sending is completed by the send () function.
This system creates two key threads in the main program to complete the data transmission task, namely Serial thread and Ethernet thread. The function of the Serial thread is to send the data stream received by the serial port through the network port, while the function of the Ethernet thread is to send the data stream sent by the network port through the serial port. The main program flow of the serial port server system based on S3C44B0 is shown in Figure 5.
Figure 5 Main program flow chart of the serial port server system based on S3C44B0
Conclusion
The serial port server system based on S3C44B0 can connect scattered serial port devices to the Ethernet to realize resource sharing and remote control functions, basically meeting the networking needs of various monitoring units in modern mines. The system has flexible control, low cost, large expansibility, and is easy to implement various complex control functions. At present, this system has been applied to the Ethernet monitoring system of the feed switch of the coal mine power supply system, which has greatly promoted the production and networking of coal mines.
Previous article:Illustration of JLINK debugging experience under ADS
Next article:ARM and GPRS network constitute a home medical monitoring system
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Proteus simulation implementation of simple single-chip calculator
- 【GD32L233C-START Review】 Second Development Board Function Review
- Technologies such as RFID enhance the security of smart IoT
- I2C Pressure Sensor
- Differences between CPU and CLA in C28x+FPU architecture and error handling techniques
- Prize-winning quiz | TE "New Energy Application Solutions White Paper"
- Why are XH connector manufacturers so stupid?
- A summary of the most downloaded electronic technical materials this week (2020.6.1~5)
- Analysis of the reasons why Lingdong MM32 cannot be burned
- New microcontroller board 2 yuan a piece great value need to buy