This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500, W5200 and W5100. One of them can be selected by enabling it in wiznet.h.

Dependents:   Embedded_web EmailButton EmailButton HTTPClient_Weather ... more

other drivers

for only W5500 / WIZ550io user, you could use

Import libraryW5500Interface

This is the Interface library for WIZnet W5500 chip which forked of EthernetInterfaceW5500, WIZnetInterface and WIZ550ioInterface. This library has simple name as "W5500Interface". and can be used for Wiz550io users also.

Committer:
jbkim
Date:
Fri May 09 01:17:51 2014 +0000
Revision:
1:8138a268fbd2
Parent:
0:b72d22e10709
Wiznet Ethernet library 1st release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jbkim 0:b72d22e10709 1 /*
jbkim 0:b72d22e10709 2 *
jbkim 0:b72d22e10709 3 * Test program for W5500 mbed Library
jbkim 0:b72d22e10709 4
jbkim 0:b72d22e10709 5 */
jbkim 0:b72d22e10709 6 #include "mbed.h"
jbkim 0:b72d22e10709 7 #include "WIZnetInterface.h"
jbkim 0:b72d22e10709 8
jbkim 0:b72d22e10709 9 #define ECHO_SERVER_PORT 5000
jbkim 1:8138a268fbd2 10 const char* ECHO_SERVER_ADDRESS = "192.168.1.229"; // Server IP address
jbkim 0:b72d22e10709 11
jbkim 1:8138a268fbd2 12 /**
jbkim 1:8138a268fbd2 13 * Setting DHCP or static
jbkim 1:8138a268fbd2 14 */
jbkim 1:8138a268fbd2 15 //#define USE_DHCP
jbkim 1:8138a268fbd2 16
jbkim 1:8138a268fbd2 17 /**
jbkim 1:8138a268fbd2 18 * Setting the platform to test
jbkim 1:8138a268fbd2 19 */
jbkim 0:b72d22e10709 20 #define LPC
jbkim 0:b72d22e10709 21 //#define ST_NUCLEO
jbkim 1:8138a268fbd2 22 //#define FRDM_KL25Z
jbkim 1:8138a268fbd2 23 //#define Seeeduino_Arch
jbkim 0:b72d22e10709 24
jbkim 0:b72d22e10709 25 #ifdef LPC
jbkim 0:b72d22e10709 26 // LPC1768 & LPC11U24
jbkim 0:b72d22e10709 27 SPI spi(p5, p6, p7); // mosi, miso, sclk
jbkim 0:b72d22e10709 28 WIZnetInterface eth(&spi, p8, p9); // spi, cs, reset
jbkim 0:b72d22e10709 29 #endif
jbkim 0:b72d22e10709 30
jbkim 0:b72d22e10709 31 #ifdef ST_NUCLEO
jbkim 0:b72d22e10709 32 // ST Nucleo
jbkim 0:b72d22e10709 33 SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
jbkim 0:b72d22e10709 34 WIZnetInterface eth(&spi, PB_6, PA_10); // spi, cs, reset
jbkim 1:8138a268fbd2 35 #endif
jbkim 1:8138a268fbd2 36
jbkim 1:8138a268fbd2 37 #ifdef FRDM_KL25Z
jbkim 1:8138a268fbd2 38 // Freescale FRDM KL25Z
jbkim 1:8138a268fbd2 39 SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
jbkim 1:8138a268fbd2 40 WIZnetInterface eth(&spi, PTD0, PTA20); // spi, cs, reset
jbkim 0:b72d22e10709 41 #endif
jbkim 0:b72d22e10709 42
jbkim 1:8138a268fbd2 43 #ifdef Seeeduino_Arch
jbkim 0:b72d22e10709 44 // Seeedstudio Arch
jbkim 1:8138a268fbd2 45 SPI spi(P1_22, P1_21, P1_20); // mosi, miso, sclk
jbkim 1:8138a268fbd2 46 WIZnetInterface eth(&spi, P0_2, P0_0); // spi, cs, reset
jbkim 1:8138a268fbd2 47 Serial pc(P1_13, P1_14); // tx, rx
jbkim 1:8138a268fbd2 48 #else
jbkim 1:8138a268fbd2 49 Serial pc(USBTX,USBRX);
jbkim 1:8138a268fbd2 50 #endif
jbkim 0:b72d22e10709 51
jbkim 1:8138a268fbd2 52 #ifndef USE_DHCP
jbkim 1:8138a268fbd2 53 // for static IP setting
jbkim 0:b72d22e10709 54 const char * IP_Addr = "192.168.1.120";
jbkim 0:b72d22e10709 55 const char * IP_Subnet = "255.255.255.0";
jbkim 0:b72d22e10709 56 const char * IP_Gateway = "192.168.1.111";
jbkim 1:8138a268fbd2 57 #endif
jbkim 0:b72d22e10709 58
jbkim 0:b72d22e10709 59
jbkim 0:b72d22e10709 60 int main()
jbkim 0:b72d22e10709 61 {
jbkim 1:8138a268fbd2 62 uint8_t mac[6];
jbkim 1:8138a268fbd2 63
jbkim 1:8138a268fbd2 64 mbed_mac_address((char *)mac); // using the MAC address in LPC11U24 or LPC1178
jbkim 1:8138a268fbd2 65 // mac[0] = 0x00; mac[1] = 0x08; mac[2] = 0xDC; mac[3] = 0x00; mac[4] = 0x00; mac[5] = 0x00;
jbkim 1:8138a268fbd2 66 // you can alo use WIZ550io's MAC address by enabling "USE_WIZ550IO_MAC" in wiznet.h
jbkim 1:8138a268fbd2 67
jbkim 0:b72d22e10709 68 pc.printf("Start\n");
jbkim 1:8138a268fbd2 69 #ifdef USE_DHCP
jbkim 1:8138a268fbd2 70 int ret = eth.init(mac); //Use DHCP
jbkim 1:8138a268fbd2 71 #else
jbkim 1:8138a268fbd2 72 int ret = eth.init(mac, IP_Addr, IP_Subnet, IP_Gateway); // static
jbkim 1:8138a268fbd2 73 #endif
jbkim 0:b72d22e10709 74
jbkim 0:b72d22e10709 75 if (!ret) {
jbkim 0:b72d22e10709 76 pc.printf("Initialized, MAC: %s\n", eth.getMACAddress());
jbkim 0:b72d22e10709 77 } else {
jbkim 0:b72d22e10709 78 pc.printf("Error eth.init() - ret = %d\n", ret);
jbkim 0:b72d22e10709 79 return -1;
jbkim 0:b72d22e10709 80 }
jbkim 0:b72d22e10709 81
jbkim 0:b72d22e10709 82 ret = eth.connect();
jbkim 0:b72d22e10709 83 if (!ret) {
jbkim 0:b72d22e10709 84 pc.printf("IP: %s, MASK: %s, GW: %s\n",
jbkim 0:b72d22e10709 85 eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
jbkim 0:b72d22e10709 86 } else {
jbkim 0:b72d22e10709 87 pc.printf("Error eth.connect() - ret = %d\n", ret);
jbkim 0:b72d22e10709 88 return -1;
jbkim 0:b72d22e10709 89 }
jbkim 0:b72d22e10709 90
jbkim 0:b72d22e10709 91 TCPSocketServer server;
jbkim 0:b72d22e10709 92 server.bind(ECHO_SERVER_PORT);
jbkim 0:b72d22e10709 93 server.listen();
jbkim 0:b72d22e10709 94
jbkim 0:b72d22e10709 95 while (true) {
jbkim 0:b72d22e10709 96 pc.printf("\nWait for new connection...\n");
jbkim 0:b72d22e10709 97 TCPSocketConnection client;
jbkim 0:b72d22e10709 98 server.accept(client);
jbkim 0:b72d22e10709 99 //client.set_blocking(false, 1500); // Timeout after (1.5)s
jbkim 0:b72d22e10709 100
jbkim 0:b72d22e10709 101 pc.printf("Connection from: %s\n", client.get_address());
jbkim 0:b72d22e10709 102 char buffer[256];
jbkim 0:b72d22e10709 103 while (true) {
jbkim 0:b72d22e10709 104 int n = client.receive(buffer, sizeof(buffer));
jbkim 0:b72d22e10709 105 if (n <= 0) break;
jbkim 0:b72d22e10709 106
jbkim 0:b72d22e10709 107 client.send_all(buffer, n);
jbkim 0:b72d22e10709 108 if (n <= 0) break;
jbkim 0:b72d22e10709 109 }
jbkim 0:b72d22e10709 110
jbkim 0:b72d22e10709 111 client.close();
jbkim 0:b72d22e10709 112 }
jbkim 0:b72d22e10709 113 }