RTC + TCP-IP + SNTP or NTP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTC + TCP-IP + SNTP or NTP

1,999 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DiamondS on Fri Jul 22 02:02:05 MST 2011
Hello,

I'm using lpc17xx (for now LPC1769 LPCXpresso board) arm MCU's and i need to synchronise my RTC clock with other server using NTP or SNTP protocol. I haven't tried it yet, but maybe someone has and can share his/her success with me.
0 Kudos
Reply
2 Replies

1,519 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Sat Jul 23 14:33:15 MST 2011
The simplest approach for NTP regardless of tcp-ip stack specifics is:

1) Create a UDP packet with a 48 byte payload all set to zeroes, then set the first byte with the Version and Mode values:
#define NTP_PORT    123
#define NTP_VERSION 3
#define NTP_MODE    3                    // 3 - client

    ((u8_t *)payload)[0] = (NTP_VERSION<<3) | NTP_MODE;
2) Send the request, on receiving the response, also consisting of 48 bytes, the server's Transmit Timestamp will be in the last 64 bit word. The upper 32 bits of that word holds the whole number of seconds since midnight 1/1/1900 GMT.

You can shift the epoch to 1/1/1970 with:
#define EPOCH_SHIFT 2208988800UL        // epoch-shifter: 1970-1900 in seconds

    u32_t time = ((u32_t *)payload)[10] - EPOCH_SHIFT
Then you can use the C standard <time.h> library to convert the data into year, month, day .. etc.
0 Kudos
Reply

1,519 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Fri Jul 22 12:05:33 MST 2011
I have done this with lwIP 1.3.2 using the raw api. Which IP stack are you using?

I could post up the code if you are interested.
0 Kudos
Reply