Share this

Embedded Web Server Design with CAN Bus

2026-04-06 08:01:59 · · #1

This paper designs and implements an embedded web server that can connect a computer network device based on the TCP/IP protocol to a low-level field network based on the CAN bus protocol.

introduction

Embedded systems refer to hardware and software systems centered around microprocessors or microcontrollers, embedded in various products or engineering applications. Embedded Internet technology, formed by the combination of embedded systems and Internet technology, is an emerging technology that has developed in recent years with the popularization of computer network technology. It expands the functionality of existing embedded systems by adding Internet access capabilities, creatively proposing the use of low-cost microcontrollers as microprocessors, enabling embedded devices, rather than PC systems, to directly access the Internet. In this paper, the hardware structure and software functions of an embedded web server are implemented using the Ubicom SX52 microcontroller with an external Ethernet control chip RTL8019AS. The shift from traditional DCS-based industrial control systems to embedded web structures can effectively reduce costs because there is no need to develop proprietary GUIs, it is more convenient for end users, and it improves remote access capabilities for fault detection and equipment maintenance.

1. Embedded Web Server Hardware Design and Implementation

Embedded system hardware typically includes a microcontroller, memory peripherals, and I/O ports, with the embedded microcontroller at its core. To meet internet connectivity requirements, the embedded microcontroller must not only perform traditional control functions but also functions related to internet connectivity. Ubicom's SX52 chip can relatively easily implement the TCP/IP protocol, so we chose it as our microcontroller.

The most crucial aspect of enabling embedded devices to access the Internet is, in principle, implementing the TCP/IP protocol. Another key issue is the selection of the transmission medium. We adopt the most common connection mode, namely connecting to the Internet via Ethernet, and utilize a network interface controller to implement the data link layer protocol. The most widely used network driver chip in embedded systems is the NE2000 compatible series network chip, which has advantages such as convenient interface, simple driver, and low resource consumption, making it particularly suitable for embedded systems. We selected the RTL8019AS chip, which has relatively high performance and stable supply.

The embedded web server uses an SX52 microcontroller as its processor. The Ethernet driver chip RTL8019AS is connected to the Ethernet via a coupling isolation filter HR61101G and an RJ45 interface. It is equipped with two expansion interfaces, RS232 and CAN bus, which can connect devices with RS232 interfaces or devices that use the CAN bus protocol to the Ethernet.

The RS232 interface uses the MAX232CPE chip, the CAN bus controller uses the Philips SJA1000 chip, and the CAN transceiver uses the Philips PCA82C250. The data flow is as follows: request and control information comes from the local area network (LAN), is sent to the RTL8019AS via RJ45, the RTL8019AS is responsible for stripping the header and trailer information of the Ethernet frame, and sending the processed data packet to the SX52's TCP/IP protocol stack. The protocol stack parses the datagram to obtain the original request and control information. The request and control information is then encapsulated in CAN protocol format by the SJA1000 before communicating with the field CAN bus devices. The response to requests and controls comes first from the LAN, and the process is exactly the reverse.

The SX52 has 5 I/O ports, totaling 40 pins. In this design, RC0-RC7 of the SX52's Port C are used to connect to the RTL8019AS's data ports SD0-SD7. The SX52's Port B handles both address selection and read/write control functions, and is used to connect to the RTL8019AS's address and read/write control pins. This approach ensures smooth communication while fully utilizing the flexible configuration of the SX52 chip's I/O ports, maximizing the conservation of the microcontroller's hardware resources. The RTL8019AS's base address selection pins IOS0-IOS3 are grounded, resulting in an I/O base address of 300H (0011 00000 000), so address lines SA9 and SA8 are connected to +5V. Since the register address offset ranges from 00H to 1FH (32 pins in total), corresponding to addresses from 300H to 31FH, only address lines SA0-SA4 need to be connected to the SX52's RB0-RB4, with the remaining address lines grounded. The chip's IORB and IOWB pins are read/write signal lines, connected to the RB6 and RB5 read/write control pins of the SX52.

The RTL8019AS is compatible with both 8-bit and 16-bit operations. In Figure 2, IOCS16 is the 16-bit I/O selection pin. When the RTL8019AS is powered on and reset, if this pin is low, the RTL8019AS will select 8-bit mode; if this pin is high, the RTL8019AS will select 16-bit mode. Since the SX52 is an 8-bit data bus, an 8-bit bus mode is required (only 8 data lines SD0-SD7 are needed for each byte read or written), so this pin is grounded. The RTL8019AS has three operating modes: the first is jumper mode, where the chip's I/O and interrupts are determined by jumpers; the second is plug-and-play mode, automatically configured by software; and the third is jumperless mode, where the chip's I/O and interrupts are determined by the contents of the external 93C46. Common network cards typically only support the second and third modes for the RTL8019AS. In embedded applications, the 93C46 is not used to reduce costs and wiring.

This design uses the first method, where the JP pin is connected to a high level. The AUI pin determines whether to use the AUI or BNC interface. A high level uses the AUI interface, and a low level uses the BNC interface, supporting 8-wire twisted pair or coaxial cable. This design uses twisted pair as the communication medium, so this pin is grounded. The RTL8019AS uses pins TPIN+, TPIN-, TPOUT+, and TPOUT- to connect to the coupling isolation filter HR61101G, and uses an RJ45 connector to achieve Ethernet connection. The SJA1000 is an independent CAN communication controller that supports the CAN2.0B protocol and operates at a frequency of 6–24 MHz. Its AD0–AD7 are address-data multiplexed lines, connected to the D port RD0–RD7 of the SX52. When a remote user queries the CAN bus data in the field through a web server, the SJA1000 is responsible for parsing the CAN bus data of the field control unit, sending it to the SX52, and then transmitting it to the network. The PCA82C250 is the interface between the CAN protocol control and the physical bus. It provides transmit capability to the bus and receive capability to the CAN controller, supporting a speed of 1 Mbps. To ensure the SX52 and SJA1000 work together, the hardware design uses a shared hardware reset line for both chips, ensuring synchronous hardware resets for the SX52 and SJA1000.

The AT24C256 is an I2C bus EEPROM, typically used to store user settings such as IP address and gateway. In this design, it is used to store static web pages. SCL is connected to pin RA4 of the SX52, and SDA is connected to pin RA5. The MAX232CPE performs the conversion between RS-232 and TTL levels, providing a local interface for convenient debugging and maintenance. TXD is connected to pin RA5 of the SX52.

The MAX232CPE performs RS232 to TTL level conversion, providing a local interface for convenient debugging and maintenance. TXD connects to pin RA2 of the SX52 microcontroller, RXD connects to pin RA3, and RS-RXD and RS-TXD are RS232 levels, standard serial port levels. Data can be input from the serial port to the SX52 microcontroller, which then sends the data to the RTL8019AS for transmission.

2. Embedded Web Server Software Design and Implementation

2.1 Implementation of Ethernet Interface Driver

To connect an embedded web server to Ethernet, the RTL8019AS needs to be programmed to send and receive Ethernet frames, essentially implementing the functionality of a network card driver in a PC. The Ethernet controller driver is used to set the RTL8019AS's operating state and mode, allocate buffers for sending and receiving data, and complete the reception and transmission of Ethernet frames by reading and writing to the address and data ports. First, the RTL8019AS needs to be reset and set to jumper mode; then, the operating parameters of the RTL8019AS are set to enable its operation; finally, the RAM of the RTL8019AS is read and written to complete the reception and transmission of data packets.

2.2 Implementation of the Embedded Web Server TCP/IP Protocol Stack

The TCP/IP protocol stack is a crucial implementation of the SX virtual peripherals and forms the foundation for interconnecting SX processor-based application systems with the Internet. This protocol stack facilitates the development of Internet-based embedded application systems. Ethernet data transmission uses MAC addresses for identification, and the ARP protocol provides the conversion between IP addresses and MAC addresses used at the data link layer. To ensure system communication over Ethernet, the ARP protocol must first be implemented.

Because embedded web servers need to communicate over the Internet, the IP protocol must be implemented at the network layer, as well as the ICMP protocol to report data transmission errors. At the application layer, the main function is to implement access control for remote hosts via a browser, so the HTTP protocol must be implemented. Since HTTP is based on TCP, and TCP is designed for reliable data stream transmission, and given the application's reliability requirements, TCP is used at the transport layer, with simplified versions developed specifically for HTTP.

After system initialization, the main program loop begins. The main program loop consists of two main parts: unpacking received Ethernet data frames and encapsulating and sending data to be transmitted. Received Ethernet data frames are unpacked for use by the application; data to be transmitted is encapsulated and sent in Ethernet frame format, ensuring that all computers within the Ethernet network using the TCP/IP protocol can receive the data frames.

2.3 Implementation of Embedded Web Server Application

Industrial field data must be uploaded to the Ethernet network via an embedded web server before it can be used by users. Therefore, the development of the communication program between network users and the web server is a crucial part of this project. The embedded web server in this project primarily implements real-time data publishing functionality. Real-time data includes temperature, equipment operating status information, communication status information, clock information, etc. The embedded web server publishes this real-time data as web pages to the Internet, allowing remote clients to access and view the real-time industrial field information published by the server.

This design adopts the Browser/Server (B/S) development model. Developing embedded web server applications using this approach has many advantages, such as reduced client requirements, easier distributed client deployment, and lower client development and maintenance costs. However, due to the limited resources of the SX microcontroller, programming a server built with a microcontroller to implement real-time dynamic data browsing is quite demanding. Running the program on the server side also limits speed, and any unilateral adjustment to the web interface or program structure will require a complete system overhaul, resulting in poor system flexibility and scalability. Therefore, if only the B/S access method is used in this design, its functionality cannot be fully realized.

To address the drawbacks of developing web server applications using the traditional B/S (Browser/Server) model, an improvement scheme is proposed. The following two improvements are made to overcome the shortcomings of the traditional B/S access model.

① Socket programming is used to allow part of the server program to run on the client side, enabling dynamic webpage display of real-time data in the client's browser. In the improved solution, Java applet technology is used to achieve real-time browsing of dynamic data.

② Instead of writing HTML into assembly code and decoding it into web pages in the browser, this approach utilizes an embedded web server with an extended EEPROM24C256 connected to the SX52 microcontroller to store the web files to be viewed. When the browser interacts with the web server, the HTTP protocol is used to determine which resources the web server should provide to the browser via a Uniform Resource Locator (URL). This improved approach still uses a browser to access the embedded web server, but employs a client/server (C/S) model for communication, using socket programming—a combination of browser/server (B/S) and client/server (C/S) architectures.

This method accesses static web pages on a web server using a B/S (Browser/Server) architecture, with each page embedding a Java applet file. When the client's Internet Explorer browser browses this page, the Java applet's source code, identified by the page, is downloaded and executed on the client. The Java applet's source code creates a socket to communicate with the server (provided a corresponding server listener is running simultaneously on the web server), primarily to acquire real-time data for display in the browser. In fact, socket communication in Java applets is a typical client/server (C/S) access method. This combination of B/S and C/S approaches allows for effective dynamic browsing of real-time data. Furthermore, this implementation combines the advantages of both B/S and C/S architectures, offering significant flexibility.

The following is a detailed implementation of the communication process between the server and the client applet.

① Create a Socket. Use tcbLocalPortMSB and tcbLocalPortLSB to set the server listening port number, specifically 8080; use myIP3~0 to set the server IP address, specifically 192.168.1.111.

② Set the server to Listen state, waiting to receive client connections. The code for establishing a passive connection using TCP API functions is as follows: `TCPAppInit Bank TCB_BANK Mov tcbLocalPortLSB,#APPLET_PORT_LSB;` sets the TCP service port. `Mov tcbLocalPortMSB,#APPLET_PORT_MSB Jmp @TCPAppPassiveOpen;` jumps to the TCP passive connection procedure to perform port listening. `_TCPAppPassiveOpen _bank TCP_BANK mov tcpState,#TCP_ST_LISTEN clr tcpUnAckMSB clr tcpUnAckLSB retp`

③ When the TCP state is established, the connection between the two parties is established, and data transmission can begin. At this time, a new socket is created to manage the remote client service, while the original port continues to be used for listening.

④ Data transmission includes two parts: data reception and data transmission. When receiving data, the TCPAppRxBytes() function is used to obtain the number of bytes received. Based on this number, the TCPAppRxData() function is called multiple times to receive more data. After all data has been received, appropriate processing can be performed in the TCPAppRxDone() function. When sending data, the TCPAppTxBytes() function is first called to set the number of bytes to be sent. Based on this number, the TCPAppTxData() function is called to send the data. After all data has been sent, the TCPAppTxDone() function is called to confirm. The collected dynamic data is stored in the variable globTemp3.

⑤ When the TCP state is closed, the server closes the connection and no longer sends or receives data. In the actual program implementation, it is set so that after the client and server connection is established, the server sends data to the client.

3. Conclusion

The embedded web server designed in this paper adopts an improved web application development model, using Java applets to implement the client program, eliminating the need for a separate client application and simplifying user operation. It can replace traditional industrial control computers and interface cards, enabling direct internet access for field equipment data. It is compact, lightweight, and low-cost. This web server can be widely used in industrial control to network small industrial monitoring systems, and can also be applied to intelligent instruments, smart parks, environmental engineering, plant factories, industrial refrigeration, and other fields.

Read next

CATDOLL Laura Soft Silicone Head

You can choose the skin tone, eye color, and wig, or upgrade to implanted hair. Soft silicone heads come with a functio...

Articles 2026-02-22