Ethernet Interface Design for Embedded Systems Based on CP2200
2026-04-06 04:49:36··#1
Abstract: With the continuous enhancement of microcontroller processing power, embedded systems are becoming more and more complex, and control systems are becoming increasingly networked, making the research on Ethernet-based embedded systems a trend in their technological development. This paper takes the ATmega16 microcontroller and CP2200 Ethernet controller as the main hardware and TCP/IP as the protocol, analyzes the feasibility of the embedded microcontroller system accessing the Ethernet, and elaborates on its hardware design, software design and real-time performance. Keywords: Ethernet; microcontroller; embedded system; TCP/IP; real-time performance 1 Introduction Embedded systems are devices for controlling, monitoring or assisting the operation of equipment, machines and workshops. They have the characteristics of small software code, high automation and fast response speed. In recent years, they have been widely used in industrial control systems and communication fields. Embedded systems can be divided into two types according to the embedded processors used: one is a high-end embedded system with DSP and 32-bit as the microcontroller and microprocessor; the other is a low-end embedded system with 8-bit microcontroller as the microcontroller [1]. With the improvement of processing speed, storage space, production process, cost reduction, and the advantages of simple structure and easy use, microcontrollers still have great potential for development in future embedded system applications. At the same time, control systems are becoming more and more complex, and functional requirements are constantly increasing. Multiple embedded microcontroller systems need to communicate with each other, and staff also need to monitor and manage the system's operation. This requires embedded microcontroller systems to have the function of connecting to the network. However, most embedded systems are still in the stage of independent application. Even if information is transmitted between multiple microcontrollers, they are only networked using some fieldbuses. The application of these buses has its locality, and the buses are incompatible and cannot achieve a wider range of connections. Ethernet, on the other hand, is not limited. Ethernet is currently the most mature and widely used local area network technology. Connecting embedded devices to the local area network through common hubs, switches and other devices to achieve real-time network remote control and management has become a technological development trend in embedded system applications [2]. In the research of "multi-dimensional numerical control system" in this project, the EDM machine tool includes a motion control part, a pulse power supply part and an operation part. These independent embedded systems are networked using fieldbus. This paper uses the ATmega16 microcontroller and the newly released Ethernet controller CP2200 as hardware to realize the networking of various embedded microcontroller systems. 2 Hardware Design The system hardware mainly consists of four modules, as shown in Figure 1: [align=center] Figure 1 System Hardware Block Diagram[/align] 2.1 Microcontroller Selection Currently, there are many types of microcontrollers, mainly based on the 51 core or the AVR core. Microcontrollers based on the AVR core are superior to those based on the ordinary 51 core. This paper uses the ATmega16 microcontroller produced by Atmel, which is based on AVR. AVR microcontrollers adopt a Reduced Instruction Set Computing (RISC) and Harvard architecture. AVR microcontrollers generally have a watchdog timer, which helps the program resist interference, and is very important in industrial control systems and network data communication. The main features of the ATmega16 microcontroller [3]: a) 131 instructions, most of which are executed in a single clock cycle; b) 16K bytes of in-system programmable Flash, 512 bytes of EEPROM, and 1K bytes of on-chip SRAM; c) Two programmable serial USARTs and a programmable watchdog timer with an independent on-chip oscillator; d) Two 8-bit timers/counters with independent prescalers and comparators; a 16-bit timer/counter with prescalers, comparators, and capture functions, and six sleep modes. 2.2 Ethernet Controller Selection Most 8-bit microcontrollers do not integrate an Ethernet controller and require a dedicated Ethernet controller to connect to the Ethernet. The CP2200 Ethernet controller uses the latest single-chip Ethernet controller produced by Silabs. The CP2200 can provide the most widely used local area network technology and is the smallest and most efficient Ethernet controller in the industry. The CP2200 can reduce the required board area by up to 90%, minimize system cost and complexity, and enable the system to connect to the Ethernet more effectively. Its basic structure is shown in Figure 2. [align=center] Figure 2 Basic structure of CP2200[/align] The main features of the CP2200 Ethernet controller are as follows[4]: a) It contains an IEEE802.3 and is compatible with 10Base-T Ethernet Media Access Controller (MAC) and Physical Layer (PHY); b) It has a pre-set unique 48-bit MAC address, which can save most of the programming steps required by embedded systems in the product manufacturing process; c) It supports auto-negotiation, which is usually necessary for the network to understand the Ethernet functions supported by the controller. Without this mechanism or user control switch, the network will choose the default minimum communication capability, which will prevent the bandwidth and performance of the application product from being fully utilized; d) It provides a high-performance parallel external memory interface with an operating speed of up to 30Mbps, which can greatly shorten the communication time and enable the microcontroller to execute communication protocols or other programs more efficiently; e) It can operate in a temperature range of -40℃ to +85℃ with a current consumption of only 70mA, which is equivalent to 1/3 of other products; 2.3 The hardware circuit connection design provides the main circuit connection between the ATmega16 and CP2200, providing an RJ-45 interface for Ethernet connection and a serial interface (MAX232) for connecting to the next-level network or field devices. The hardware connection is shown in Figure 3. [align=center]Figure 3 Hardware Design Connection Circuit Diagram[/align] Some anti-interference component circuits and reset circuit designs are omitted in the figure. The ATmega16 has four bidirectional I/O interfaces (PA, PB, PC, PD), and the CP2200 provides dedicated address ports (A0-A7) for 8-bit mode. Here, PA0-PA7 of the ATmega16 are directly connected to the address ports A0-A7 of the CP2200. Ports PC0-PC7 are directly connected to the data bus ports D0-D7 of the CP2200. The ATmega16 controls the operating mode of the CP2200 through ports PB0-PB7. Pin SS is connected to pin CS of the CP2200 to implement the chip select function. The ATmega16's MISO and MOSI pins are connected to the CP2200's RD and WR pins respectively, enabling the microcontroller to read and write to the Ethernet controller. The ATmega16 connects to the MAX232's R1OUT and T1IN pins via pins PD14 (RXD) and PD15 (TXD) respectively, enabling the microcontroller to read and write to the serial port. The CP2200 uses Non-Mutiplexed mode and supports Intel and Motorola Bus modes. When both MUXEN and MOTEN are low, it is in Intel mode. The CP2200 is connected to an RJ-45 interface via an isolation transformer to establish an Ethernet connection. The CP2200 can use both hardware and software interrupts; here, hardware interrupts are used, so the CP2200's INT pin is connected to the ATmega16's PB2 (INT3) pin. 3 System Software Analysis and Design Ethernet uses the 802.3 standard and the TCP/IP protocol. The 802.3 standard is located at Layer 1 (Physical Layer) and Layer 2 (Data Link Layer) of the IOS/OSI model. The data transmission structure used is the IEEE 802.3 frame structure (Table 1). Table 1: IEEE 802.3 Frame Structure. Where: Destination address is the address of the station to which the frame is sent; each station has its own unique address; Data length is the total length of the data to be transmitted; Protocol header is part of the data field, containing information embedded in the data field by higher-layer protocols; Data byte length can range from 0 to 1500 bytes, but the frame must be at least 64 bytes; otherwise, padding bytes must be added; Frame checksum uses CRC. The TCP/IP protocol adopts a layered structure (based on the OIS reference model), from bottom to top: Physical Layer, Data Link Layer, Network Layer, Transport Layer, and Application Layer. The Physical Layer and Data Link Layer can be handled by an Ethernet controller. The Network Layer includes IP, ARP, and ICMP protocols, primarily handling IP addressing and responsible for sending packet sets from the source host to the destination host. The transport layer includes TCP and UDP. Its main function is to be responsible for end-to-end communication between application processes. Its purpose is to establish end-to-end connections for sessions between peer entities of the source host and the destination host in the network. The user's main program is located at the highest layer of the protocol, namely the application layer. It is mainly used to complete data acquisition and processing. The main protocols are TENET, FTP, SMTP, and DNS. There are two communication access modes between the microcontroller and the Ethernet controller: interrupt and polling. To avoid the main program from constantly polling and to simplify the program, the interrupt mode can be used [5]. In the interrupt mode, the Ethernet access driver mainly consists of the Ethernet controller interrupt service routine, the data transmission module (Figure 4), and the data reception module (Figure 5). Before the CP2200 starts working, the system needs to perform certain initialization to determine the working mode of the CP2200. [align=center]Figure 4 Data Transmission Module[/align] [align=center]Figure 5 Data Reception Module[/align] When implementing network interconnection for embedded microcontroller systems, besides some drivers, the main task is to implement the TCP/IP network protocol. The main process is shown in Figure 6. Its main function is to generate TCP and IP groups when data needs to be sent, and send them to the CP2200 for transmission; when data needs to be received, parse the IP/TCP groups and send them to the application layer for further processing. 4 Ethernet Real-Time Issues Real-time performance refers to the system's ability to respond promptly to external stimuli, often quantitatively described by the system's response time. Ethernet uses a random access protocol, namely Carrier Sense Multiple Access/Collision Detection (CSMA/CD). Under low communication load conditions, CSMA/CD has a very fast response and good real-time performance. However, when Ethernet is applied in industrial applications or under high communication load conditions, CSMA/CD will produce unpredictable delay characteristics, i.e., uncertainty problems, and cannot meet real-time requirements. Methods to improve real-time performance generally focus on software or hardware aspects. In terms of software, real-time operating systems such as RT-CSMA/CD and IEEE1588[6] are used. This technology has made some progress and has been applied in some fields, but there are still some problems to be solved. In terms of hardware, Ethernet switches are generally used to build a full-duplex switched Ethernet. This technology is widely used and relatively mature. [align=center] Figure 6 Network interconnection program flowchart[/align] 5 Conclusion Embedded systems can not only control, monitor and manage field devices or other subsystems through Ethernet technology, but also communicate with the host computer or other systems through the network to realize the network communication and control functions of the system. Moreover, the system is stable, easy to control and low in cost. The Ethernet interface of the embedded system based on CP2200 can achieve this purpose. The innovation of the author of this article is that it not only conducts hardware and software analysis on the design of the Ethernet interface of the embedded system based on CP2200, but also briefly describes the Ethernet real-time problem and improvement method. References [1] Cheng Xiaohui, Li Mingqiang, Shen Xu Design of Hardware Platform for Embedded System Based on AT89C51 Microcontroller [J]. Automation and Instrumentation. 2005.4. [2] Fu Chong, Chen Ying, et al. Design of a General-Purpose Ethernet Interface for Embedded System [J]. Journal of Shandong University, 2005.6(3).93-97. [3] ATMEL Corporation AVR Embedded Web server [Z]. USA: ATMEL Corporation 2003. [4] Silicon Laboratories Inc. CP2200/1 Complete Datasheet [Z]. USA: Silicon Laboratories Inc. 2006. [5] He Ruibo, Zhao Yingjun A Method for Connecting Ethernet and 8-bit Microcontroller [J]. Microcontroller and Embedded System Applications. 2002.7. [6] Zhang Yan, Sun Hexu, et al. Application of IEEE1588 in Real-Time Industrial Ethernet [J]. Microcomputer Information, 2005, No.9-1.