Implement the MCS-51 MCU embedded access to the Internet technology. The MCU interacts with the Internet through the ATL8019AS Ethernet controller. Use the open source TCP/IP protocol stack uIP to drive the underlying devices, and implement various application services through the uIP protocol application interface. Give the hardware design diagram and write the MCU main program. Apply this technology to realize a city center parking monitoring system.
In recent years, embedded systems represented by microcontrollers (MCU) have been widely used in industrial detection systems, intelligent instruments, security systems, smart home appliances and information appliances.
If the embedded system can be connected to the Internet, users can remotely control, monitor and transmit information through the network conveniently, quickly and cheaply. The integration of Internet technology and embedded technology not only brings unprecedented development space and opportunities for the design and development of embedded systems, but also makes Internet applications enter the era of embedded Internet. According to experts' predictions, 45% of the new services and applications on the Internet in the future will come from small embedded systems. Therefore, the Internet access technology of embedded systems will have extremely broad application prospects. How to use single-chip microcomputers to access the Internet network will become one of the hottest technologies in the future.
1 MCU Embedded Internet Access Technology
In Internet network communication, the TCP/IP protocol cluster is very large and requires a lot of system resources. The disadvantage of single-chip microcomputers is that they have limited resources and cannot accommodate the TCP/IP protocol cluster of the Internet. Therefore, the key to implementing embedded Internet access technology with single-chip microcomputers is how to implement the Internet network communication protocol stack on the limited resources of embedded devices such as single-chip microcomputers. The difficulty lies in how to use the limited resources of the single-chip microcomputer itself to process the information with the TCP/IP protocol and turn it into an IP data packet that can be transmitted on the Internet. At present, many research institutions are actively exploring the use of MCU to implement Internet access technology, and a variety of single-chip microcomputer embedded Internet technology solutions have emerged. These technical implementation solutions can be classified into the following categories.
(1) Use dedicated embedded chips. Dedicated embedded chips are single-chip microcomputers with built-in communication and control functions that can realize real-time multi-tasking operations. They provide greater system design flexibility than traditional single-chip microcomputer hardware. Such chips include Ubicom's IP2022 chip and MOXA's Nport Express chip. These chips are powerful and can implement multiple network protocols. They generally provide corresponding TCP/IP network protocol stacks. However, the price of such chips is relatively high, and users need to pay for software and hardware fees, which makes it difficult to achieve widespread market application.
(2) Embedded systems form a dedicated network and access the Internet through a PC gateway. Small embedded systems form a dedicated network through bus technology and use a PC as a gateway. The PC converts the information sent from the dedicated network into TCP/IP protocol data packets through dedicated software and then sends them to the Internet to achieve remote communication. This solution was widely used in the early days. However, the disadvantage of this solution is that it requires the use of a dedicated PC. Obviously, it is only suitable for some industrial data acquisition systems and is not easy to promote to fields such as information appliances and networked intelligent instruments.
(3) Use ordinary single-chip microcomputer and network control chip. This method is relatively simple to implement and can be expanded according to actual needs. However, it is necessary to implement the embedded TCP/IP network protocol on the single-chip microcomputer, and the workload of software programming is relatively large. Since ordinary single-chip microcomputer is used, its advantages are low cost and small size, and it is easy to promote to many occasions where embedded access to the Internet is required with extremely high cost performance. The system designed in this paper adopts this technical solution. The following will focus on analyzing its hardware and software design.
2 Interface circuit between single chip microcomputer and network card
2.1 Overall system design
Figure 1 Overall system design.
The system uses the most commonly used MCS 8051 series microcontroller, which is inexpensive and widely used. The network card uses the ATL8019AS Ethernet controller chip produced by Taiwan Realtek . Since the program code of the Internet network protocol is large, the system has added some peripheral circuits in addition to the microcontroller and the network card. Including RAM memory used as data cache and RS232 interface, the former is used as a data buffer, and the latter is used as an interface for data interaction between the microcontroller and the field equipment. The overall functional design of the system is shown in Figure 1.
In the above system design, the microcontroller mainly completes the unpacking of Internet data and the packaging of serial port RS232 data. The data packet transmitted by the remote PC reaches the Ethernet control chip RTL8019AS through the physical medium of the Internet. RTL8019AS executes the address resolution protocol and then hands it to the C8051 microcontroller. The microcontroller executes the TCP/IP protocol module, removes the TCP/IP header and hands the data to the field equipment of the data acquisition system through the RS232 serial port. On the contrary, if the field equipment sends data to the microcontroller, the microcontroller will package the data according to the TCP/IP protocol format and send it to RTL8019AS, which will be transmitted to the Internet by the network card chip. In the above way, the microcontroller completes the interaction with the Internet, thereby realizing the Internet remote control of the data acquisition system.
2.2 Interface circuit between microcontroller and network card
The single-chip microcomputer is the core of this system, so the interface circuit between the single-chip microcomputer and the network card is very critical. This system uses the 8051 series single-chip microcomputer because the 8051 single-chip microcomputer is the most commonly used single-chip microcomputer. It is inexpensive and widely used, and it is easy to reduce system costs in industrial equipment applications. At the same time, the 8051 program is concise and easy to debug. The connection circuit between the 8051 single-chip microcomputer and the Ethernet controller chip is shown in Figure 2.
Figure 2 Connection diagram between MCU and Ethernet control chip.
The 8-bit data bus D0-D7 of the 8051 microcontroller P0 port, the 5 address lines A8-A12 of the P2 port, the read signal line RD, the write signal line WR, and the 2 timer control terminals T0 and T1 are respectively connected to the corresponding signal lines of Realtek8019AS.
The Realtek8019AS chip works in 8-bit bus mode. The 8051 microcontroller drives the network control chip RTL8019AS, and the Internet access is realized after the network isolation filter HR901170A.
3 Implementation of TCP/IP protocol stack on MCU
3.1 Embedded TCP/IP Protocol Stack
The TCP/IP protocol is the core protocol of the Internet. To realize embedded access to the Internet, the TCP/IP protocol must be implemented on the microcontroller. Since the TCP/IP protocol cluster is extremely large and the resources on the microcontroller are limited, it is impossible to fully implement the TCP/IP protocol on the microcontroller. At present, many companies have developed commercial embedded TCP/IP protocol stacks based on different embedded devices. The disadvantage of these protocol stacks is that they are aimed at chips produced by specific companies and require expensive software usage fees. If this type of protocol stack is used, the designed microcontroller embedded Internet system will not have a cost-effective advantage. After comparison, the open source TCP/IP protocol stack uIP0.9 was finally selected as the design core in this system. uIP0.9 is a small embedded TCP/IP protocol stack suitable for 8/16-bit microcontrollers. Interested users can download its source code on the Internet for free and modify it to meet different application needs. The uIP0.9 protocol stack adopts a modular design, retains the protocol mechanism necessary for network communication, greatly reduces the amount of protocol code (the amount of code is about several thousand bytes), and only requires a few hundred bytes of memory to run smoothly, reducing the protocol's requirements for system resources. uIP0.9 is fully adapted to current microcontroller embedded systems.
3.2 uIP Architecture
According to the needs of embedded systems, the uIP protocol removes many uncommon functions in the TCP/IP protocol, and retains the core parts such as ARP (optional), IP, ICMP, TCP, and UDP (optional) required in network communication. The protocol is written entirely in C language, and its code occupies very little space and requires very low RAM resources. For example, the IP/ICMP/TCP core module code size is 3304 bytes, and only 360 bytes of RAM are used. Its application layer interface and device driver layer interface are very simple.
The uIP protocol focuses on the implementation of IP, ICMP and TCP protocols, and takes UDP and ARP protocols as optional modules. The architecture of the uIP protocol is shown in Figure 3.
Figure 3 uIP protocol stack structure diagram.
3.3 uIP's underlying device driver interface and application programming interface
uIP is a protocol stack that only contains three layers of network layer core protocols. uIP itself does not contain any type of underlying network drivers and upper layer applications. It only provides interface functions for users to develop and use. Therefore, in order to complete the interaction with network devices, users must implement the driver of the underlying network device in uIP according to the type of network device. For this example, the network device is the RTL8019AS network card, so the driver of the RTL8019AS network card needs to be implemented in uIP. If users need to browse and obtain field data through the http protocol on the Internet, they must also implement the WEB application service based on the HTTP protocol on uIP.
The RTL8019AS network card driver first initializes the network card chip through the function init_8019as(), which is used to set the physical address of the network card, the location and size of the send and receive buffers, etc. The second is the data sending function eth_send() and the data receiving function eth_rcve().
The uIP protocol stack implements the driver for the underlying network device through the uip_input() function in the kernel, which is the underlying device entry of the uIP protocol. It contains two global variables uip_buf and uip_len. The former is used to store the received data packets, and the latter indicates the data length in the receiving and sending buffer. The uip_input() function processes the IP packets sent from the network device driver. After processing, it returns the variable uip_len. If uip_len is 0, there is no data to be sent. If it is not 0, the network device driver eth_send() function is called to send the data of uip_len length in uip_buf to the Ethernet. The eth_rcve() function stores the received data in the buffer specified by the cache uip_buf. The system calls the uip_input() function and calls the application when necessary.
uip_periodic() can be understood as a periodic clock function, which is usually executed once a second. The microcontroller uses it to periodically poll each connection. Because the uIP protocol has to handle many timing events, such as packet retransmission and ARP table entry update. When the periodic timing is triggered, each TCP connection calls uip_periodIC(), and its TCP connection number is passed as a parameter to the uip_periodic() function. The uip_periodic() function checks the status of the connection specified by the parameter. When the uip_periodic() function returns, it checks the value of uip_len. If it is not 0, the data packet in the uip_buf buffer is sent to the network.
The application interface of the uIP protocol is used to implement application services such as web. uIP defines a macro UIP_APPCALL() as the interface for users to use. When users want to program to implement a certain application service, they only need to define the macro UIP_APPCALL() as the actual application function name. After receiving the data packet from the bottom layer, if uIP needs to send it to the upper layer application for processing, it calls UIP_APPCALL(). Different connections are determined by judging the port number of the current connection. At the same time, uIP also provides some application interface functions for users to use when programming. Commonly used uIP application interface functions are: closing connection interface function uip_close(); polling interface function uip_poll(); opening connection interface function uip_connect(), etc. By calling different application interface functions, users can implement corresponding functions.
4. Design of MCU Main Program
After adding the underlying device driver module and application service program module and correctly configuring uIP, the main part of the software writing is the MCU main program function. The main program depends on what functions the user needs to achieve. For this example of connecting to the Internet through an Ethernet card to realize WEB application services, the MCU main program first starts the initialization work, including timer initialization, network card chip initialization, UIP protocol stack initialization, user application initialization, etc. [5]. After completing the initialization, the main program will continue to query. If a new IP data packet arrives on the network card, it will be sent to the uip_input() function for processing; if no new data packet arrives, the uip_priodic() function will process the timer event. Since the uIP protocol stack is written in C language, in order to facilitate the interaction between the MCU main program and the uIP protocol, the MCU main program also uses C language as the development language. The following is part of the design code of the MCU main program.
The link layer part of the TCP/IP protocol stack is completed by the network controller RTL8019AS, and the network layer and transport layer are processed by the microcontroller.
The application layer can be completed in the MCU according to the needs, or it can be transferred from the MCU to the user or terminal device. In addition to WEB services, other application layer services such as SMTP protocol support functions can also be written in corresponding codes according to needs.
5 System Testing
On the basis of completing the above work, we designed a parking monitoring and management system for the downtown parking lot. Since the downtown parking lot has a very busy business volume and the parking spaces are often saturated, not only managers but also customers often need to grasp the parking space vacancy information of the parking lot in real time. The front end of the data acquisition system monitors the vacancy status of each parking space through sensors. And timely feedback information to the single-chip microcomputer, the feedback information includes the parking space vacancy status, parking start time and duration, etc. Based on this, the monitoring system calculates the number of vacant parking spaces in the entire parking lot, and returns the information to the client, and displays it on the LED display screen at the entrance and exit of the parking lot in the form of announcement information. It is convenient for customers to make decisions. The billing information calculated according to the parking duration can also be displayed on the client. Combined with the above requirements, we implemented an embedded Web server on the single-chip microcomputer. Http web pages can complete applications such as receiving data, sending web page data, closing connections, and can dynamically update data in real time. The client uses the most commonly used Windows operating system and Internet Explorer browser, and the client does not need to install other special service programs. The system is only set to a maximum of 4 concurrent clients to access the single-chip microcomputer Web server. Figure 4 is the result of accessing the single-chip microcomputer Web server.
Figure 4. Client accessing the MCU Web server.
6 Conclusion
Embedded network communication is an emerging application field of embedded industry in recent years. Since the MCS-51 series of single-chip microcomputers have a long history and wide application, their low price, and the uIP protocol stack can be used for free, the products using this design scheme have low cost and less auxiliary hardware, so that the terminal price will not increase too much due to embedded access to the Internet. It has a very high cost performance and is easy to market. At present, the system developed based on this technology has been successfully applied in the busy parking lot monitoring system in the urban area. It can be applied to other single-chip microcomputer systems based on the 51 core with only a little improvement. This system can help industrial applications such as intelligent information appliances and production equipment monitoring to realize embedded Internet with a good cost performance.
Previous article:Wireless transmission system efficiency detection based on 51 single chip microcomputer wireless power supply module
Next article:The realization of data display of common anode digital tube using 51 single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 12:46
- Popular Resources
- Popular amplifiers
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- Implicit interactions supported by sensors and actuators in driver assistance systems
- Design and implementation of electric vehicle information security gateway
- CVPR 2023 Paper Summary: Video: Low-Level Analysis, Motion, and Tracking
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
- MSP430 Remote Upgrade Solution
- Calculate the frequency of the sinusoidal signal collected by msp430
- I recently used a chip that is compatible with both RS232 and RS485, but I don't know which pins are A and B for RS485.
- [ATmega4809 Curiosity Nano Review] Configuring GPIO using MCC
- Today at 10:30 AM Microchip Live | Manufacturing Logistics Challenges of Key Security Provisioning: Advantages of Discrete Secure Components
- Multisim circuit simulation does not oscillate?
- In order to solve network congestion, what black technologies does Wi-Fi 6 use?
- [Atria AT32WB415 Review] 1. Unboxing, installation and use of AT32 IDE development environment (especially error resolution)
- Please ask the experts about STM32, FSMC control LCD problem?
- Made a JLINK OB and shared the production process and experience