DSP, Micros & Memory

Using embedded Web servers within applications

5 June 2002 DSP, Micros & Memory

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.

Hardware interfaces

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.

TCP/IP protocols

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.

Figure 1. TCP/IP stack model
Figure 1. TCP/IP stack model

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.

Figure 2. Generic embedded Web server featuring the PIC18F6720
Figure 2. Generic embedded Web server featuring the PIC18F6720

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.


Share this article:
Share via emailShare via LinkedInPrint this page

Further reading:

V2X: The future of vehicle communications
29 January 2020, Avnet South Africa , Editor's Choice, Telecoms, Datacoms, Wireless, IoT
A recent report by Juniper Research forecasts that more than 62 million vehicles will be capable of vehicle-to-vehicle communication by 2023; up from just over 1,1 million in 2019.

STM32 system-on-chip for LoRa
29 January 2020, Avnet South Africa , Telecoms, Datacoms, Wireless, IoT
Powering the search for sustainability through smart infrastructure and logistics, smart industry and smart living, STMicroelectronics has revealed the world’s first LoRa system-on-chip (SoC) for connecting ...

EERAM memory solutions retain data at power loss
29 January 2020, Avnet South Africa , DSP, Micros & Memory
Microchip Technology announced a new family of Serial Peripheral Interface (SPI) EERAM memory products that offers system designers up to 25% cost savings over the current serial non-volatile ram (NVRAM) ...

32-bit Arm microcontrollers
29 January 2020, Hi-Q Electronics , DSP, Micros & Memory
Renesas Electronics unveiled the Renesas Advanced (RA) family of 32-bit Arm Cortex-M microcontrollers (MCUs). They deliver a combination of optimised performance, security, connectivity, peripheral ...

Non-inverting converters for buck or boost operation
29 January 2020, Avnet South Africa , Power Electronics / Power Management
Texas Instruments introduced a family of four high-efficiency, low-quiescent-current (IQ) buck-boost converters that feature tiny packaging with minimal external components for a small solution size. ...

Lithium-ion/polymer battery packs catalogue
29 January 2020, Avnet South Africa , Technical Literature
The latest edition of the Avnet Abacus standard lithium-ion/polymer battery packs catalogue covers the company’s portfolio of primary and secondary cells from leading battery manufacturers, as well as ...

Applications processor for machine learning at the edge
29 January 2020, EBV Electrolink , DSP, Micros & Memory
NXP Semiconductors has expanded its advanced EdgeVerse portfolio with the i.MX 8M Plus application processor – the first i.MX family to integrate a dedicated Neural Processing Unit (NPU) for advanced ...

Tiny buck-boost converters
25 November 2019, Avnet South Africa , Power Electronics / Power Management
Texas Instruments introduced a family of four high-efficiency, low-quiescent-current (IQ) buck-boost converters that feature tiny packaging with minimal external components for a small solution size. ...

NXP further expands LPC5500 MCU family
25 November 2019, EBV Electrolink , DSP, Micros & Memory
NXP Semiconductors announced the availability of its LPC552x/S2x microcontroller (MCU) family, further extending its efficient LPC5500 MCU series with the second of seven families planned for the series. ...

Ultra-small LDO linear regulator
25 November 2019, Avnet South Africa , Power Electronics / Power Management
Texas Instruments introduced an ultra-low-power low-dropout (LDO) linear voltage regulator with what it claims is the industry’s lowest quiescent current (IQ) of sub-25 nA. The new regulator features ...