There is nothing new about a low-cost microcontroller (MCU) running a TCP/IP stack and serving Web pages. Many MCUs incorporate a TCP/IP stack implementation, allowing them to be connected to the Internet. Although this is a perfectly valid use, such devices can be even more useful when used inside applications. Many applications use a status or diagnostic port to provide a view of their internal operations. Considerable effort can be needed to develop this interface, its protocols and the resulting software to run on an external computer or handheld to display the information. It is much easier to use a global standard already in use: the Internet and Web browsers. Almost everyone has surfed the Web and can easily navigate a Web page. The use of embedded Web servers to display status and diagnostic information using Web pages not only cuts development time for the system designer, but also reduces training and equipment costs when the system is deployed.
Most large systems already incorporate an embedded network, usually RS232, RS485, I2C, or CAN, from which information about system operation can be obtained. A low-cost, 8-bit MCU can interface to this network and communicate with the various sub-systems to get status information and provide control over those systems. The MCU also has an Internet interface. This allows a field service technician to connect a standard PC to the system using the serial or Ethernet port. Since the IP address of the MCU is the same on all systems, the configuration of the PC is automatically handled when the PC boots. The technician only needs to start the Web browser to begin checking status or changing parameters in the system.
The Internet interface comes in two varieties: serial or Ethernet. The serial interface is the same as that used by many people today to connect using modems. In this case, a modem is not needed, as the stack on the MCU emulates one. The only hardware requirement is a level-shift circuit that translates the ±15 V RS232 levels to the 0 V and +5 V digital levels of the MCU. Many inexpensive devices, such as a MAX232 or DS275, will do this.
The Ethernet interface also requires an interface IC, which needs to be significantly more complex than the one needed for RS232. This device buffers packets to be transmitted or packets that have been received, checking the addresses and checksums of packets, and the interface to the network media. Ethernet interface devices include the Realtek RTL8019AS or the Crystal CS8900A. In addition to the interface IC, a clock source and a media interface device such as a transformer are required.
Serial interfaces can take advantage of the integrated serial port provided on many microcontrollers. However, Ethernet interface devices have yet to become embedded and usually implement some type of PC bus interface such as ISA or PCI. Therefore, the interface to the MCU usually requires a slew of I/O pins for address, data and control.
The second part of the Internet hardware is the microcontroller. The MCU must first be able to interface to the existing network in the application. Implementing the Web server with integrated peripherals also saves CPU overhead for the main system, compared to implementing a virtual peripheral. I2C is very popular in environmental monitoring for rack-mounted equipment such as servers. RS485 is used in many industrial applications. CAN also serves industrial applications as well as automotive busses. One example of a device that would satisfy most of these requirements is the PIC18F6720 Flash microcontroller from Microchip Technology. This device has a USART interface capable of supporting RS232 and RS485, an SPI module and an I2C module. It contains 128 KB of program memory and 3,8 KB of data memory, which is sufficient to implement the interface to the application network and the TCP/IP stack.
Now we must define the set of Internet protocols neded to implement the embedded Web server. The requirements can be seen in Figure 1, which shows a TCP/IP stack model containing several layers.
The Physical Layer provides the low-level interface between the MCU and the physical media. For serial interfaces, this may include firmware to emulate a modem and/or routines to transfer data using the serial port. An Ethernet interface requires routines to control the I/O pins used to connect to the address, data and control lines. The Physical Layer transfers data bits or bytes between the media and the next layer up in the stack.
The Data Link Layer converts the raw data from the Physical Layer into logical frames that the next layer up recognises. A serial interface will typically use one of two protocols: Serial Line Interface Protocol (SLIP) or Point-to-Point Protocol (PPP). SLIP is a very simple method of breaking data into frames using a delimiting character in the stream of data. PPP is a more complex protocol providing services such as compression and many other advanced features. PPP is usually used in serial interfaces for dial-up connections to the Internet, but the simplicity of SLIP may be more suited to a control and diagnostic port.
The Network Layer is responsible for handling addressing of messages and routing messages from source to destination. It is used to translate hardware addresses such as an Ethernet address into logical addresses such as an IP address. The protocols used in this layer are the Address Resolution Protocol (ARP), Internet Control Message Protocol (ICMP) and Internet Protocol (IP). ARP translates the physical address into the logical address. ICMP provides a method of communicating errors and other messages between two nodes on the network. One of the most useful features of ICMP for debugging embedded systems is the echo request and reply, or 'PING'. This feature allows one system to see if another system is connected to the network. IP is the backbone of the Internet. Some of the features of IP are the addressing and routing of packets, fragmentation and re-assembly of packets of data, packet timeout and prioritisation of packets.
The Transport Layer controls the flow of data between nodes on a network and divides the data stream into more manageable sizes for the surrounding layers. It can also provide error checking, error handling and acknowledgement of data based on the protocol. The two main protocols used in the Transport Layer are User Datagram Protocol (UDP) and Transmission Control Protocol (TCP). UDP is a connectionless-based protocol where packets of data are transmitted without any handshaking or acknowledgement of reception. It is significantly simpler than TCP and can be used successfully in many embedded applications. TCP, on the other hand, provides a reliable method of delivering packets to the destination. TCP provides full duplex transmission and can compensate for packets that arrive out of order. It can change its operation to maximise delivery based on network delays and packet sizes. TCP is an extremely robust protocol, but comes at a price of significantly increased CPU overhead.
So far we have not discussed what to do with the data, only how to get it from one place to another. The Application Layer provides the necessary services to interpret the data being received. This layer provides services such as file transfer, mail and Web browsing. The two important protocols for embedded systems are Trivial File Transfer Protocol (TFTP), based on a UDP transport, and HyperText Transfer Protocol (HTTP), based on a TCP transport. TFTP is a simple method used to transfer data to the MCU, such as new firmware to be self programmed into Flash program memory or new Web pages to display. HTTP is the underlying protocol of Web browsers. It interprets the HyperText Markup Language (HTML) and co-ordinates the transfer of data and graphics to support the Web page. The Web browser is the most universally-used graphical user interface (GUI) in the world and, most importantly, it is free!
There are several applications that can take advantage of an embedded Web server for diagnostics and control. The modern car has many subsystems that communicate over a network. This is usually a CAN network, which communicates between the engine control module, the traction control module, the body control module and others. An aeroplane has a similar system, with many subsystems that control the engines, control surfaces and flight systems. Industrial applications that have sensors measuring a process can display flow rates, temperatures, pressure, etc. Racks of equipment such as servers will have hardware to monitor power supply voltages, temperatures and fan speeds. Figure 2 shows an example of what a generic system looks like when based on a PIC18F6720. All these applications have the potential to provide an intuitive interface to a service technician to troubleshoot, diagnose and modify the system and probably are already using 8-bit MCUs.
Using the protocols of the TCP/IP suite best suited to an embedded environment, an 8-bit microcontroller can create a self-contained embedded Web server capable of interfacing to the application network and the outside world. It can provide an easy-to-use GUI to see the status of a system and control the application. Most importantly, it reduces development time and costs associated with diagnostic equipment and training field service technicians.
Source material reproduced with permission from ECN Magazine, November 2001.
For further information about Microchip Technology products, contact local representatives: Avnet Kopp, 011 444 2333, Azona, 012 665 2880, Memec SA, 021 674 4103 or Tempe Technologies, 011 452 0530.