The Example of SNTP for W5500 running on Nucleo board

Dependencies:   SNTPClient WIZnet_Library mbed

Fork of SNTP_Ethernet_W5500 by Raphael Kwon

Files at this revision

API Documentation at this revision

Comitter:
sjallouli
Date:
Tue Dec 29 19:18:35 2015 +0000
Parent:
0:2176bc9b0007
Commit message:
SNTP Using NUCLEO-F411RE and WIZnet5500

Changed in this revision

W5500Interface.lib Show diff for this revision Revisions of this file
WIZnet_Library.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/W5500Interface.lib	Fri Dec 19 05:49:31 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/teams/EthernetInterfaceW5500-makers/code/W5500Interface/#713b6d2aaefb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnet_Library.lib	Tue Dec 29 19:18:35 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/WIZnet/code/WIZnet_Library/#cb8808b47e69
--- 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