Utilize embedded systems to connect to the Internet to implement Web server applications

Publisher:电子设计探索者Latest update time:2024-03-05 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Embedded Internet refers to the process in which electronic devices directly connect to the Internet through embedded modules instead of PCs and interact with the Internet for information. At present, the Internet has become the largest and most information-rich Internet network in the world. Users even hope that household appliances, instruments, and data collection and control equipment in industrial production can also be connected to the Internet, because this means that users can remotely control, monitor, and transmit information through the network conveniently, quickly, and cheaply. Scientists from Bell Labs in the United States predict that in the future there will be hundreds or thousands of times more super-embedded Internet servers than in the PC era. The integration of Internet technology and embedded technology has brought unprecedented development space and opportunities to the design and product development of embedded systems.


1. Hardware system design of microcontroller embedded Web application

In the design of the hardware system, this article uses the high-performance 8-bit AVR (Advanced RISC) microcontroller AT90S8515 developed by ATMEL. This microcontroller has a built-in 8 KB programmable Flash, uses a reduced instruction set, supports C language and assembly language, and is compatible with MCS 8051 The performance of this series of single-chip microcomputers has been greatly improved, and it is widely used in the current development of single-chip microcomputers. Therefore, AT90S8515 microcontroller is used as the microprocessor of the embedded system, and the embedded system is connected to the Internet through the network control chip. The hardware system block diagram is shown in Figure 1.

Utilize embedded systems to connect to the Internet to implement Web server applications

In the hardware system composition of the circuit, pay attention to the following points:

(1) Interface circuit between microcontroller and network card chip

The 8-bit data bus PA0"PA7" provided by the AT90S8515 microcontroller corresponds to the SD0"SD7 pin connected to the network card respectively; the five address lines PC0"PC4 correspond to the SA0"SA4 pin connected to the network card; the read signal line RD, the write signal line WR and Connect the corresponding signal lines of RTL8019AS. Reset is controlled through PB0, and PB1 chip select address is enabled. The external clock circuit microcontroller is 8 MHz, and the network card chip is 20 MHz.

(2) Memory expansion circuit

Generally, the on-chip data memory capacity of a microcontroller is 64 KB. This storage space is too small when developing a microcontroller Web application system. Therefore, the data storage needs to be expanded, and the expansion capacity depends on the system data usage. For Web applications, a large storage space is required to store data such as web pages, so this system uses the static RAM HM62256 chip as the memory expansion circuit.

(3) RTL8019AS working mode

RTL8019AS has 3 working modes: jumper mode, plug-and-play mode and RT jumper-free mode. In embedded applications, in order to reduce the complexity of the system, the microcontroller should connect as few unnecessary chips as possible. So choose RTL8019AS to work in jumper mode. Its IOCS16B pin is connected to a pull-down resistor, and the JP pin is connected to high level.

(4) MAX232 serial port level conversion circuit

At the field control end, since the output of the microcontroller is TTL level, the output of the field data acquisition system (such as a sensor) is EIA level, and the MAX232 chip can complete the bidirectional level conversion between the microcontroller and the field data acquisition system.

(5) Network isolation filter interface circuit

A network isolation filter HR901170A is required at the network access end. HR901170A mainly protects the system circuit, reduces signal common mode interference, and completes signal transmission. HR901170A has an internal RJ45 interface that can be directly connected to the Internet.


2. TCP/IP protocol implementation of embedded Internet

2.1 Embedded TCP/IP protocol

Software programming is the key to implementing embedded Web systems. Data encapsulation and analysis in Web communication are all implemented by microcontroller software. The software implementation mainly includes two parts: first, the implementation of the simplified TCP/IP protocol stack on the microcontroller, and the layer-by-layer packaging, frame sealing, and transmission of data; the second is the implementation of the microcontroller Web application service.

Embedded Web composed of microcontrollers is often used in special and dedicated fields and generally does not require too many functions, which is very different from network applications on PCs. The TCP/IP protocol that supports PCs for Internet communication is a very large protocol cluster. The microcontroller chip does not have enough space resources, so considering both embedded network applications and microcontroller space resources, there is no need to implement the complete TCP/IP protocol on the microcontroller. Currently, there is no unified standard TCP/IP protocol software for implementing embedded Internet on the market. Developers need to develop a set of embedded TCP/IP protocols suitable for microcontrollers according to the needs of specific applications. The workload is extremely large and the development cycle is long. long. A relatively simple and easy-to-implement approach is to use a small, free and open source TCP/IP protocol developed by Adam Dunkels of the Swiss Academy of Computer Science, namely the uIP protocol stack, which is specially written for 8-bit and 16-bit microcontrollers. The code size of uIP is 3 304 B, and the demand for the microcontroller RAM is 360 B, which is far smaller than the resource requirements of the TCP/IP protocol. Detailed description and application examples of uIP can be found in the reference literature.

2.2 uIP drives underlying network device RTL8019AS

uIP is a protocol stack that only contains 3-layer 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 user development and use. Therefore, in order to complete the interaction with the underlying network device, the user must implement the driver of the underlying network device in uIP according to the type of network device. The network device used in this article is the RTL8019AS network card, so the driver for the RTL8019AS network card needs to be implemented in uIP.

The RTL8019AS driver includes: RTL8019AS chip initialization, chip reset, and data sending and receiving. RTL8019AS chip initialization can be completed through the initialization function void init_8019 (void). The chip reset performs a reset operation through the RSTDRV pin on the chip, which is active high.


3. Software implementation of embedded Web server on microcontroller

3.1 Establishment of Web server

After performing the above work, the user can establish a Web server and realize communication between different microcontrollers or workstations through the uIP protocol. The communication between the web server and the client browser uses the HTTP protocol. Embedded systems often need to collect the current data information of the system and send it to the client browser according to the user's instructions. In order to realize this dynamic interaction between the client browser and the Web server, it is necessary to use the Common Gateway Interface CGI (Common Gateway Interface) on the server side. Interface) technology. CGI is a program that runs on the server. It analyzes and processes the data information sent by the user to the server, completes the creation and processing of dynamic file resources, and then returns the user information to the client.

After the Web server is initialized, the server waits for the client's connection request. The client browser enters the server's IP address and sends a physical address resolution protocol (ARP) request packet. The server responds after receiving it. After receiving the response packet, the client sends a Hypertext Transfer Protocol (HTTP) packet. After receiving the HTTP packet, the server begins to establish a TCP connection with the client and respond to this packet. The client disconnects after receiving the response packet, and the server detects that the client has disconnected and disconnects at the same time.

3.2 Web server data processing process

When the system's network card receives a data packet sent from the network, it first analyzes whether the destination address is consistent with its own physical address. If it is inconsistent, the packet is discarded; if it is consistent, the network data is read and analyzed. If it is an ARP request packet, it is transferred to the ARP handler and an ARP reply packet is sent to the client. If it is an IP packet, it is handed over to the IP layer for processing, and the Ethernet header is removed at the same time [4-5]. The IP layer analyzes what data packet the IP packet belongs to according to the protocol field in the IP header. If it is a UDP packet, it is discarded; if it is an ICMP request packet, an ICMP response packet is sent to the client; if it is a TCP packet and the IP address and port are If the number is correct, the data packet is received. After the data is unpacked, the data part is output through the serial port to control the MAX232 field device. On the contrary, if the scene sends data to the microcontroller through the serial port, the microcontroller will package the data according to the TCP protocol format and send it to the RTL8019AS, which will send the data to the LAN. If necessary, when receiving serial port data, the data preprocessing can be completed first, and then the processed data can be sent to the LAN. The specific processing process is shown in Figure 2.

Utilize embedded systems to connect to the Internet to implement Web server applications

3.3 Web server programming on microcontroller

The uIP protocol stack provides an application program interface called macro UIP_APPCALL for users to use when designing applications. To implement the Web Server service on the microcontroller, first define the macro as an application function name, and then implement the HTTP protocol in this function. After completion, users can access the microcontroller Web server from any client within the LAN. If you assign a public IP address, this web server can also be accessed from the Internet. The implemented program is as follows:

[1] [2]
Reference address:Utilize embedded systems to connect to the Internet to implement Web server applications

Previous article:CS5210 HDMI to VGA solution design information
Next article:Design and application of light ship hydrometeorological measured data collection system using MSC1210Y5

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号