资源预览内容
第1页 / 共37页
第2页 / 共37页
第3页 / 共37页
第4页 / 共37页
第5页 / 共37页
第6页 / 共37页
第7页 / 共37页
第8页 / 共37页
第9页 / 共37页
第10页 / 共37页
亲,该文档总共37页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Ethernet Shield on Arduino - a webserver exampleProject note Arduino Ethernet Shield V1.0 1. SchematicThe Arduino Ethernet Shield V1.0 is dedicated for the Arduino boards. It uses the Microchips ENC28J60 SPI based stand-alone Ethernet controller (download datasheet here) and a compatible RJ45 socket with magnetics. Since the ENC28J60 is a 3V3 device that only drive 3V3 logic level output but capable of accepting 5V logic input, a 5V CMOS/TTL quad positive AND gates 74HCT08D is used to convert the 3.3 logic level output to 5V logic level.Fig 1. Arduino Ethernet Shield schematic 2. Software StructureThe Ethernet Shield software is in the format of Arduino library, which you can download from here. The library is implemented based on tuxgraphics.orgs open-source TCP/IP stack for Atmega88 and ENC28J60. The main files in the library are etherShield.cpp a wrapper cpp file, as an Arduino library interface with tuxgraphics code ip_arp_udp_tcp.c simplified TCP/IP stack implementation enc28j60.c ENC28J60 SPI routines net.h network protocol definitions 3. TCP/IP implementationThe standard TCP is a protocl to establish a connection. To do this, a number of packets needs to be exchaged between two sides first to establish the connection; then data packets can be exchaged. Usually a complicated state-machine is needed to implement the TCP protocol. For Auduinos ATMEGA168, a 8-bit AVR microcontroller with 1K SRAM, it is impossible to implement the full TCP stack. Also the webpage for 8-bit microcontroller that normally is used to control a relay or read a temperature sensor etc., is very simple. Therefore, instead of implementing full TCP protocl, a single data packet TCP protocol is used. You webpage contents, including all html tags, must be in one packet. The length of packet is limited by the SRAM size, currently half of the RAM space (500 bytes) is used for network Packet buffer. It is sufficient for simple webpages as shown below.4. Ethersheild library installation & modificationFirst download the ethershield library here, then copy & unzip the library in your Arduino IDE library directory (for example arduino-0010/hardware/libraries/). There are three examples in the ethershield library, you might need to change the ip address in the example sketch (.pde) files. The ip address must be a free address with your network rangestatic uint8_t mymac6 = 0x54,0x55,0x58,0x10,0x00,0x24; static uint8_t myip4 = 192,168,1,15; static char baseurl=; Also you might like to change the webpage contents in the print_webpage funtion. Note that the webpage contents are stored in the PROGMEM (using PSTR declaration) to save the precious SRAM space. 5. ExamplesThree examples are included in the ethershield library ethershield_ping.pde a PING example ethershield_webserver.pde a general webserver example ethershield_web_temperature.pde a webserver with temperature sensor (DS18B20) readings ethershield_web_switch.pde New Webserver example, switch on/off LED#include etherShield.h/ please modify the following two lines. mac and ip have to be unique/ in your local area network. You can not have the same numbers in/ two devices:static uint8_t mymac6 = 0x54,0x55,0x58,0x10,0x00,0x24; static uint8_t myip4 = 192,168,1,15;static char baseurl=;static uint16_t mywwwport =80; / listen port for tcp/www (max range 1-254)#define BUFFER_SIZE 500 static uint8_t bufBUFFER_SIZE+1; #define STR_BUFFER_SIZE 22static char strbufSTR_BUFFER_SIZE+1;/定义了两个数组一种是uint8_t buf(501),一种是strbuf(23)EtherShield es=EtherShield();/ prepare the webpage by writing the data to the tcp send buffer/准备网页向tcp发送寄存器写入数据uint16_t print_webpage(uint8_t *buf, byte on_off);int8_t analyse_cmd(char *str);/ LED cathode 连接到 the Pin4, anode to 5V through 1K 电阻#define LED_PIN 4void setup() /*初始化 enc28j60*/ es.ES_enc28j60Init(mymac); es.ES_enc28j60clkout(2); / 变换输出时钟change clkout from 6.25MHz to 12.5MHz delay(10); /* Magjack leds configuration, 参见 enc28j60 datasheet, page 11 */ LEDA=green绿灯 LEDB=yellow黄灯/ 0x880代表 PHLCON LEDB=on, LEDA=on 灯AB都亮/ enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x880);delay(500);/ 0x990代表 PHLCON LEDB=off, LEDA=off 灯AB都灭/ enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x990);delay(500);/ 0x880 is PHLCON LEDB=on, LEDA=on/ enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x880);delay(500);/ 0x990 is PHLCON LEDB=off, LEDA=off/ enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x990);delay(500);/ / 0x476 is PHLCON LEDA=links status绿灯表达已连接, LEDB=receive/transmit红灯表达正在发送或接受数据 / enc28j60PhyWrite(PHLCON,0b0000 0100
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号