![](/media/cache/group/WIZnet_logo_001.jpg.50x50_q85.jpg)
The Example of SNTP for W5500
Dependencies: SNTPClient W5500Interface mbed
Fork of SNTP_Ethernet_W5500 by
main.cpp@0:2176bc9b0007, 2014-12-19 (annotated)
- Committer:
- xeon011
- Date:
- Fri Dec 19 05:49:31 2014 +0000
- Revision:
- 0:2176bc9b0007
The Example of SNTP for W5500
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xeon011 | 0:2176bc9b0007 | 1 | #include "mbed.h" |
xeon011 | 0:2176bc9b0007 | 2 | #include "EthernetInterface.h" |
xeon011 | 0:2176bc9b0007 | 3 | #include "SNTPClient.h" |
xeon011 | 0:2176bc9b0007 | 4 | |
xeon011 | 0:2176bc9b0007 | 5 | |
xeon011 | 0:2176bc9b0007 | 6 | int main() { |
xeon011 | 0:2176bc9b0007 | 7 | // EthernetInterface eth; |
xeon011 | 0:2176bc9b0007 | 8 | // change for W5500 interface. |
xeon011 | 0:2176bc9b0007 | 9 | #if defined(TARGET_LPC1114) |
xeon011 | 0:2176bc9b0007 | 10 | SPI spi(dp2, dp1, dp6); // mosi, miso, sclk |
xeon011 | 0:2176bc9b0007 | 11 | EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset |
xeon011 | 0:2176bc9b0007 | 12 | |
xeon011 | 0:2176bc9b0007 | 13 | #elif defined(TARGET_LPC1768) |
xeon011 | 0:2176bc9b0007 | 14 | SPI spi(p11, p12, p13); // mosi, miso, sclk |
xeon011 | 0:2176bc9b0007 | 15 | EthernetInterface eth(&spi, p14, p15); // spi, cs, reset |
xeon011 | 0:2176bc9b0007 | 16 | |
xeon011 | 0:2176bc9b0007 | 17 | #elif defined(TARGET_LPC11U68) |
xeon011 | 0:2176bc9b0007 | 18 | SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk |
xeon011 | 0:2176bc9b0007 | 19 | EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io |
xeon011 | 0:2176bc9b0007 | 20 | |
xeon011 | 0:2176bc9b0007 | 21 | #else |
xeon011 | 0:2176bc9b0007 | 22 | #warning "The Device is Undefined" |
xeon011 | 0:2176bc9b0007 | 23 | #endif |
xeon011 | 0:2176bc9b0007 | 24 | |
xeon011 | 0:2176bc9b0007 | 25 | spi.format(8,0); // 8bit, mode 0 |
xeon011 | 0:2176bc9b0007 | 26 | spi.frequency(7000000); // 7MHz |
xeon011 | 0:2176bc9b0007 | 27 | wait(1); // 1 second for stable state |
xeon011 | 0:2176bc9b0007 | 28 | |
xeon011 | 0:2176bc9b0007 | 29 | eth.init(); //Use DHCP |
xeon011 | 0:2176bc9b0007 | 30 | //eth.init("192.168.11.111", "255.255.255.0", "192.168.11.1"); //Use Static IP |
xeon011 | 0:2176bc9b0007 | 31 | eth.connect(); |
xeon011 | 0:2176bc9b0007 | 32 | printf("IP Address is %s\n\r", eth.getIPAddress()); |
xeon011 | 0:2176bc9b0007 | 33 | |
xeon011 | 0:2176bc9b0007 | 34 | SNTPClient sntp("time.nist.gov", 40); // timezone: Korea, Republic of |
xeon011 | 0:2176bc9b0007 | 35 | sntp.connect(); |
xeon011 | 0:2176bc9b0007 | 36 | |
xeon011 | 0:2176bc9b0007 | 37 | datetime time; |
xeon011 | 0:2176bc9b0007 | 38 | #if 0 // execute once.. |
xeon011 | 0:2176bc9b0007 | 39 | while (sntp.getTime(&time) != true) { |
xeon011 | 0:2176bc9b0007 | 40 | ; |
xeon011 | 0:2176bc9b0007 | 41 | } |
xeon011 | 0:2176bc9b0007 | 42 | printf("%d-%d-%d, %d:%d:%d\r\n", time.yy, time.mo, time.dd, time.hh, time.mm, time.ss); |
xeon011 | 0:2176bc9b0007 | 43 | #else // infinete loop.. |
xeon011 | 0:2176bc9b0007 | 44 | while (1) { |
xeon011 | 0:2176bc9b0007 | 45 | if(sntp.getTime(&time) == true) { |
xeon011 | 0:2176bc9b0007 | 46 | printf("%d-%d-%d, %d:%d:%d\r\n", time.yy, time.mo, time.dd, time.hh, time.mm, time.ss); |
xeon011 | 0:2176bc9b0007 | 47 | wait(1.0); |
xeon011 | 0:2176bc9b0007 | 48 | } |
xeon011 | 0:2176bc9b0007 | 49 | else { |
xeon011 | 0:2176bc9b0007 | 50 | printf("failed receive..\r\n"); |
xeon011 | 0:2176bc9b0007 | 51 | } |
xeon011 | 0:2176bc9b0007 | 52 | } |
xeon011 | 0:2176bc9b0007 | 53 | #endif |
xeon011 | 0:2176bc9b0007 | 54 | } |