The Example of SNTP for W5500 running on Nucleo board
Dependencies: SNTPClient WIZnet_Library mbed
Fork of SNTP_Ethernet_W5500 by
Diff: main.cpp
- Revision:
- 1:c4d6fee8d958
- Parent:
- 0:2176bc9b0007
diff -r 2176bc9b0007 -r c4d6fee8d958 main.cpp --- a/main.cpp Fri Dec 19 05:49:31 2014 +0000 +++ b/main.cpp Tue Dec 29 19:18:35 2015 +0000 @@ -1,54 +1,74 @@ #include "mbed.h" -#include "EthernetInterface.h" +#include "WIZnetInterface.h" #include "SNTPClient.h" +/* +* WIZnet 5500 Config for nucleo 411 +*/ +Serial pc(SERIAL_TX, SERIAL_RX); +SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk -int main() { -// EthernetInterface eth; -// change for W5500 interface. -#if defined(TARGET_LPC1114) - SPI spi(dp2, dp1, dp6); // mosi, miso, sclk - EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset +#define USE_DHCP 1 -#elif defined(TARGET_LPC1768) - SPI spi(p11, p12, p13); // mosi, miso, sclk - EthernetInterface eth(&spi, p14, p15); // spi, cs, reset +const char * IP_Addr = "192.168.2.72"; +const char * IP_Subnet = "255.255.255.0"; +const char * IP_Gateway = "192.168.2.2"; +//unsigned char MAC_Addr[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +unsigned char MAC_Addr[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xDD }; -#elif defined(TARGET_LPC11U68) - SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk - EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io +int main() +{ + pc.baud(115200); // console terminal to 115200 baud + spi.frequency(1000000); + WIZnetInterface ethernet(&spi,D10, D3); + + pc.printf("Ethernet Init\r\n"); +#if USE_DHCP + int ret = ethernet.init(MAC_Addr); #else - #warning "The Device is Undefined" + int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); #endif - spi.format(8,0); // 8bit, mode 0 - spi.frequency(7000000); // 7MHz - wait(1); // 1 second for stable state - - eth.init(); //Use DHCP - //eth.init("192.168.11.111", "255.255.255.0", "192.168.11.1"); //Use Static IP - eth.connect(); - printf("IP Address is %s\n\r", eth.getIPAddress()); - - SNTPClient sntp("time.nist.gov", 40); // timezone: Korea, Republic of - sntp.connect(); + if (!ret) + { + pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); + ret = ethernet.connect(); + + if (!ret) + { + pc.printf("IP: %s, MASK: %s, GW: %s\r\n", ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); + } + else + { + pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); + exit(0); + } + } + else + { + pc.printf("Error ethernet.init() - ret = %d\r\n", ret); + exit(0); + } + + printf("IP Address is %s\n\r", ethernet.getIPAddress()); - datetime time; -#if 0 // execute once.. - while (sntp.getTime(&time) != true) { - ; + SNTPClient sntp("time.nist.gov", 6); // timezone: PST + sntp.connect(); + + datetime time; + + while (1) + { + if(sntp.getTime(&time) == true) + { + printf("%d-%d-%d, %d:%d:%d\r\n", time.yy, time.mo, time.dd, time.hh, time.mm, time.ss); } - printf("%d-%d-%d, %d:%d:%d\r\n", time.yy, time.mo, time.dd, time.hh, time.mm, time.ss); -#else // infinete loop.. - while (1) { - if(sntp.getTime(&time) == true) { - printf("%d-%d-%d, %d:%d:%d\r\n", time.yy, time.mo, time.dd, time.hh, time.mm, time.ss); - wait(1.0); - } - else { - printf("failed receive..\r\n"); - } + else + { + printf("failed receive..\r\n"); } -#endif + + wait(1.0); + } } \ No newline at end of file