Vous êtes sur la page 1sur 7

Abstract The rapid penetration of the internet networks into todays modern houses and personal gadgets (e.g.

smart phone and smart pads) have opened up avenues for a tremendously useful and interesting embedded system application:Ethernet interface for an embedded system.For eg we could note down the temperature in a room and display it in a central webpage which could be accesed by any system connected to the same network.These applications can be implemented by integrating the TCP/IP stack used in the Ethernet protocol into an embedded system by interfacing it with the micro-controller. Common hardwired solutions for the above available today would include Tlk100,WIZnet W5100, W5300, Microchip ENC28J60(wired) and the Microchip ZG2100MC WIFI module(wireless).The advantage of using the Hypertext Transfer Protocol (HTTP) server in the embedded system is that we dont have to develop a special client application to communicate with the embedded system. All we need is to use any standard browser that comes with your personal computer operating system or gadget to talk to the embedded system. The HTTP server uses a simple text called Hypertext Markup Language (HTML) to interact with the browser (client application) through the TCP/IP protocol. Introduction Here we will look into the implementation of ethernet interfacing using the W5100.The WIZnet W5100 is a single IC Ethernet solution with a built-in TCP/IP stack and it is equipped with 16 KB of internal transmit/receive buffer memory. It acts as an interface between the micro-controller and the Ethernet network. We can host a web-page in the W5100 by initializing its registers and writing the HTML code into the transmit memory. The micro-controller can communicate with the W5100 using parallel communication(GPIO pins) or SPI(serial peripheral interface). Physically the W5100 is connected to the network using the RJ45 standard socket. It can support up-to 4 sockets. The micro-controller needs to take care of the socket programming and register initializing, but is shielded from the W5100s internal Ethernet engine operations. The programmer can control the W5100 through the micro-controller. The W5100 has an inbuilt Ethernet physical layer and appropriate connecting pins to the RJ45 socket. The W5100 has both 3.3V and 5V modes and requires a simple external voltage regulation circuit. It has a a compact 80-pin LQFP package. It contains internal registers for both socket settings and micro-controller interfacing. These are initialized by the micro-controller's program. We can set the IP address among other properties for the the web-page hosted in the W5100 and access it by simply typing the IP address in any web browser. So any device that is connected to the network and that can support a simple web-browser can access the embedded system.

The TCP/IP protocol:Basics TCP/IP has many layers. In an architectural model, a layer does not define a single protocolit defines a data communication function that may be performed by any number of protocols. Because each layer defines a function, it can contain multiple protocols, each of which provides a service suitable to the function of that layer. A dependency, however, exists between the layers. Because every layer is involved in sending data from a local application to an equivalent remote application, the layers must agree on how to pass data between themselves on a single computer. The upper layers rely on the lower layers to transfer the data across the underlying network. Protocols (which compose the various layers) are like a pile of building blocks stacked one upon another. Because of this structure, groups of related protocols are often called stacks or protocol stacks. Data is passed down the stack from one layer to the next, until it is transmitted over the network by the network access layer protocols. The four layers in this reference model are crafted to distinguish between the different ways that the data is handled as it passes down the protocol stack from the application layer to the underlying physical network. At the remote end, the data is passed up the stack to the receiving application. The individual layers do not need to know how the layers above or below them function; they only need to know how to pass data to them. Each layer in the stack adds control information (such as destination address, routing controls, and checksum) to ensure proper delivery. This control information is called a header and/or a trailer because it is placed in front of or behind the data to be transmitted. Each layer treats all of the information that it receives from the layer above it as data, and it places its own header and/or trailer around that information. These wrapped messages are then passed into the layer below along with additional control information, some of which may be forwarded or derived from the higher layer. By the time a message exits the system on a physical link (such as a wire), the original message is enveloped in multiple, nested wrappersone for each layer of protocol through which the data passed. When data is received, the opposite happens. Each layer strips off its header and/or trailer before passing the data up to the layer above. information received from a lower layer is interpreted as both a header/trailer and data.

------------------------------| Application |<------ end-to-end connection ------>| Application | |--------------| |--------------| | TCP |<--------- virtual circuit --------->| TCP | |--------------| ----------------|--------------| | IP |<-- DG -->| IP |<-- DG -->| IP | |--------------| |-------+-------| |--------------| | Subnetwork 1 |<-------->|Subnet1|Subnet2|<-------->| Subnetwork 2 | -----------------------+----------------------HOST GATEWAY HOST

Applications and utilities reside in host, or end-communicating, systems. TCP provides a reliable, virtual circuit connection between the two hosts. IP provides a datagram (DG) transport service over any intervening subnetworks, including local and wide area networks. The underlying subnetwork may employ nearly any common local or wide area network technology. The term gateway is used for the device interconnecting the two subnets, a device usually called a router in LAN environments. The RJ45 standard The RJ-45 connector is commonly used for network cabling and for telephony applications. Although used for a variety of purposes, the RJ-45 connector is probably most commonly used for 10Base-T and 100Base-TX Ethernet connections. 1 TX_D1+ Transmit data + 2 TX_D1- Transmit data 3 RX_D2+ Receive data + 4 BI_D3+ 5 BI_D37 BI_D4+ 8 BI_D4Micro-controller to TCP/IP stack As mentioned before the micro-controller can communicate with the W5100 either through SPI or Parallel interface. In both of those cases they are required to have a common ground. Parallel interface: The registers of the W5100 can be accessed using the GPIO pins of the micro-controller. We would need a 14 bit address pins(14 GPIO pins),8 bit data bus (8 GPIO pins) and 5 control pins:Reset,parallel/SPI enable,Read enable( Active low),Write enable (Active low)and Chip select (Active low). Bi-directional Data+ Bi-directional DataBi-directional Data+ Bi-directional Data-

6 RX_D2- Receive data -

For operation the reset pin is held high and the parallel enable pin is held low. To write into the W5100's internal registers the following steps are followed. 1.Make the Chip select (/cs),read (/rd),write(/wr) pins high.(Configured as output pins) 2.Put the 14 bit address and 8 bit data on the address and data buses respectively.(Configured as output pins) 3.Make the /cs and /wr pins low to write. The data is now written into the W5100's registers. 4.Make the /cs,/rd,/wr pins high. To read into the W5100's internal registers the following steps are followed. 1.Make the Chip select (/cs),read (/rd),write(/wr) pins high. 2.Put the 14 bit address on the address bus(Configured as output pins). 3.Make the /cs and /rd pins low to read. The data is now written into the data bus(Configured as input pins). Store the value in a variable. 4.Make the /cs,/rd,/wr pins high. SPI interface: We can write/read data to and from the W5100 through SPI as well. This requires only 5 pins to transfer data to/from the internal registers of the W5100. Here the Micro-controller acts as the master and the W5100 is the slave,that is the clock supplied for the communication is from the micro-controller. However this method needs extra clock cycles to transfer data. For operation the SEN/Parallel enable and reset pins are set high. The pins required for communication are SCLK Serial Clock (output from master) /SCS Slave Chip Select (output from master, active low) MOSI Master Output, Slave Input (output from master) MISO Master Input, Slave Output (output from slave)

The address bits,data bits used for parallel interfacing are pulled low while the /cs,/wr,/rd are pulled high. To transfer any data through SPI the following steps are followed :1. Configure Input/Output direction on SPI Master device pins. /SCS (Slave Chip Select) : Output pin SCLK (Serial Clock) : Output pin MOSI (Master Out Slave In) : Output pin MISO (Master In Slave Out) : Input pin

2. Configure /SCS as High 3. Configure the registers on SPI Master device. SPI Enable bit on SPCR register (SPI Control Register) Master/Slave select bit on SPCR register SPI Mode bit on SPCR register

SPI data rate bit on SPCR register and SPSR register (SPI State Register)

4. Configure /SCS as Low (data transfer start) 5. Write desired value for transmission on SPDR register (SPI Data Register). To read send the read opcode (0x0F),address(expanded to 16 bits) in order from MSB to LSB and to read, start reading on MISO(8 bits) after the address is transferred. (After writing 8 bits into the SPDR wait for completion of transaction and then continue). To write send the write opcode (0xF0),address(expanded to 16 bits) and data(8 bits) in order from MSB to LSB. 6. After all data transmission ends, configure /SCS as High Initializing the W5100 server To initialize the W5100 based server we need to set certain properties of the server. The essential ones are: Gateway Address(GAR) - 4 byte data Source address register (MAC address) - 6 byte data This W5100 register will represent the unique hardware identification in the network. The MAC address is assigned and managed by Institute of Electrical and Electronics Engineers (IEEE) for each NIC (Network Interface Card) manufacturer where the first 3 bytes of 6 bytes MAC address is used to identify the organization that issued the identifier and are known as the OUI (Organizationally Unique Identifier). IP Address (SIPR) - 4 byte data Subnet mask 4 byte data

RX and TX buffer Memory Size - 1 byte data

Each of these have a fixed memory location in the W5100.Before writing this data onto the W5100 we need to software reset it by writing 0x80 into the Mode register (MR). Now any system connected to the same gateway on the network can connect to the embedded web-server. It can ping this server successfully. Configuring and using the web server A primitive HTTP server works by listening to any request from the client (browser) for any HTTP GET or POST request through the TCP/IP port 80 (standard HTTP server port). Once the client sends this request to the HTTP server, the HTTP server will respond to this client request by sending the HTTP response header (HTTP/1.0 200 OK and Content-Type: text/HTML) followed by a blank line and then the HTML text to the client. After it transfers all the HTML text to the client, the HTTP server automatically disconnects the established connection with the client. The HTML text sent to the client is the web-page code. It could be a form or a simple display page,etc. The W5100 has a Socket Status register (S0_SR).The micro-controller should monitor it continuously and take appropriate response depending on the value of the register.

Initialize socket for TCP/IP The W5100 supports a number of protocols. For TCP/IP we need to write appropriate opcodes into the Socket mode register and the Socket port registers (for HTTP it is 80) and then write the open opcode into the socket command register. Then we wait till the socket status register's value changes to the listen opcode after we write then listen command into the the socket command register. If there is any interruption in this process we should close the socket and start over again. Start interaction with client When the client sends a request the socket status register value changes to a particular value. If the client is requesting the page for the first time then it sends a GET request and if its requests on updating the present web-page then it sends a POST request. In either case for a primitive web server you would send a new web page maybe with updated values .In case of a form in a post request it would have the updated form values. The embedded system can respond to the same. Reading Request from client When the client sends the request the data is stored in the RX buffer,who's starting pointer offset is specified by the Rx Received Size Pointer Register. Then the data is read from the RX buffer using this offset. Sending the Updated Web-Page On reading the request the micro-controller can update the web page string and give appropriate outputs to the actuators in the system. To send the web-page we wait till the TX_Buffer is big enough by reading the TX Free Size Register. If the TX_buffer is not cleared by a particular timeout period we disconnect and initialize socket again. We write the web-page (which is in a form of a string on the micro-controller side) into the TX_buffer and update the offset register accordingly. Then we write the send opcode into the socket command register and wait till the server is done sending the buffer data which is signaled by a change in the command register value. If the web-page size exceeds that of the maximum buffer size we split the string and send it in chunks. After we send the data the server disconnects from the connection that was established,closes the port and reinitializes the socket. Combining the embedded system functions and the web-server code on the micro-controller code. One effective way of combining the embedded system functions and the web-server part on the micro-controller code would be to run the less critical process in a watchdog timer interrupt. For example the micro-controller could be continuously scanning the Status register ,updating the web-page,doing the web server transactions and updating variables while the watchdog interrupts the processor at fixed intervals. In these intervals the processor can update the embedded system. However when the micro-controller is involved in a web-server transaction its better to disable the interrupt to avoid disconnections. The WIZnet W5100 has been adapted to the very popular Atmega based platform Arduino in the form of an Ethernet shield. The W5100 socket driver for the Atmel AVR micro-controller families has been provided by the Wiznet corporation. This has been widely used in many hobbyist applications and even featured in the IEEE magazine Spectrum where an employee used it to Tweet details on to a 16x2 LCD display on his office door. This has a very widespread application range due to the simplicity and

extensive network available for the platform required.

Vous aimerez peut-être aussi