Problem: NTP Server IP Cannot Be Changed From the HMI on an S7-1500
An S7-1500 CPU (for example, 6ES7 511-1AK02-0AB0, CPU 1511-1 PN) is configured in TIA Portal to perform time synchronization via NTP. The engineer wants to change the NTP server IP address at runtime from a WinCC HMI (or any VISU) without re-downloading the project. A user-program call to IF_CONF_NTP returns the existing configuration as an array, the new IP values are written into the data block, and the call is repeated — yet the CPU keeps synchronizing with the original NTP server. No error is reported, but no change takes effect either.
The root cause is rarely the IP string itself. It is almost always one of three issues: the MODE input is wrong, the data block tags are not mapped to the block's InOut variables, or the runtime write is confused with the engineering-time configuration in the CPU properties. This article documents the correct procedure using the IF_CONF_NTP function block from the SIMATIC library.
Prerequisites
- S7-1500 CPU with firmware V2.0 or higher (CPU 1511-1 PN 6ES7 511-1AK02-0AB0 firmware V2.6 or later recommended).
- TIA Portal V15.1 or higher (V16 / V17 preferred for current library revisions).
- The
IF_CONF_NTPfunction block from the global SIMATIC library > "Time synchronization" must be available in the project. - An NTP server reachable from the CPU's PROFINET interface. Confirm with
pingfrom a service laptop before commissioning. - The PLC program must have write access to CPU system data (always available; no special protection needed).
- HMI tags pointing to the same data block tags that are wired to
IF_CONF_NTPmust be configured with the correct length for the STRING parameters (typically 64 characters).
IF_CONF_NTP is the only supported way to overwrite that configuration from the user program.Why IF_CONF_NTP Appears to Do Nothing
Three common root causes are seen in the field:
-
MODE = 0: The block returns the current NTP configuration (read) but never writes. The status word shows
DONE=TRUE, but no change is made. - MODE = 1: A full overwrite is performed. On firmware older than V2.1 this can fail silently with STATUS = 0x8080 ("Mode not supported") if a previous server is already configured.
- HMI tag length mismatch: WinCC writes a STRING shorter than 15 characters (for example, 8 characters for a 32-bit IP). The trailing CR/LF or null terminator shifts the IP by one byte, and the CPU rejects the address with STATUS = 0x8081 ("Invalid IP format").
The Siemens support entry "How do you set the IP address of the NTP server variably via the user program of the S7-1500 CPU?" documents the correct procedure and confirms that MODE = 2 is required when modifying an existing NTP configuration in place.
IF_CONF_NTP Interface Reference
The block is found in TIA Portal under Libraries > Global libraries > SIMATIC > S7-1500 > Time synchronization > IF_CONF_NTP. The interface is documented in the TIA Portal information system and the S7-1500 system manual.
| Parameter | Declaration | Data Type | Description |
|---|---|---|---|
| REQ | Input | BOOL | Edge-triggered execute; a positive edge starts the operation. |
| MODE | Input | UINT | 0 = read, 1 = write (overwrite all), 2 = modify (change individual servers). |
| SERVER_1_IP | InOut | STRING[64] | Primary NTP server IPv4 address as dotted string ("192.168.0.250"). |
| SERVER_2_IP | InOut | STRING[64] | Optional secondary NTP server. Empty string disables. |
| SERVER_3_IP | InOut | STRING[64] | Optional tertiary NTP server. Empty string disables. |
| SERVER_4_IP | InOut | STRING[64] | Optional quaternary NTP server. Empty string disables. |
| INTERVAL | InOut | TIME | Synchronization interval (10 s to 24 h, typical 60 s to 600 s). |
| DONE | Output | BOOL | Set for one cycle after successful completion. |
| BUSY | Output | BOOL | TRUE while the block is processing. |
| ERROR | Output | BOOL | TRUE if an error occurred. |
| STATUS | Output | WORD | Detailed status / error code (see table below). |
STATUS Word Decoding
| STATUS (hex) | Meaning | Remedy |
|---|---|---|
| 0000 | No error, configuration applied. | — |
| 7000 | No job active (idle state). | Raise REQ edge. |
| 7001 | First call with REQ=TRUE, BUSY=TRUE. | Wait for DONE. |
| 7002 | Subsequent call, BUSY=TRUE. | Continue polling. |
| 8001 | Internal error (firmware inconsistency). | Update CPU firmware. |
| 8080 | MODE not supported in current firmware. | Use MODE=1 or upgrade CPU firmware to V2.1+. |
| 8081 | Invalid IP format (malformed STRING). | Check STRING length and content; strip trailing characters. |
| 8082 | Interval out of range (<10 s or >24 h). | Clamp INTERVAL to T#10s..T#24h. |
| 8090 | No NTP configuration present. | Download engineering config once, then use MODE=2. |
| 80A1 | Resource locked (e.g., online via TIA). | Disconnect online connection before REQ. |
Step-by-Step Implementation
Step 1 — Create the Configuration Data Block
Add a global DB (for example, DB_NTP_Config) with the following tags. The STRING length must match what the block expects; do not reduce it.
DATA_BLOCK "DB_NTP_Config"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
NON_RETAIN
STRUCT
Server1_IP : STRING[64]; // e.g., '192.168.10.250'
Server2_IP : STRING[64]; // '' to disable
Interval : TIME; // T#60s typical
Mode : UINT; // 2 for modify
Req : BOOL;
Done : BOOL;
Busy : BOOL;
Error : BOOL;
Status : WORD;
END_STRUCT;
END_DATA_BLOCK
Step 2 — Call IF_CONF_NTP in OB1 (or Cyclic OB)
Wire the InOut variables directly to the data block tags. Do not use temporary variables — the block reads the STRING header to determine the actual length.
// OB1 — cyclic call, edge-triggered on a HMI command tag
IF "HMI_Cmd_NTP_Apply" AND NOT "DB_NTP_Config".Busy THEN
"DB_NTP_Config".Req := TRUE;
END_IF;
"IF_CONF_NTP_DB"(REQ := "DB_NTP_Config".Req,
MODE := "DB_NTP_Config".Mode,
SERVER_1_IP := "DB_NTP_Config".Server1_IP,
SERVER_2_IP := "DB_NTP_Config".Server2_IP,
INTERVAL := "DB_NTP_Config".Interval,
DONE => "DB_NTP_Config".Done,
BUSY => "DB_NTP_Config".Busy,
ERROR => "DB_NTP_Config".Error,
STATUS => "DB_NTP_Config".Status);
IF "DB_NTP_Config".Done OR "DB_NTP_Config".Error THEN
"DB_NTP_Config".Req := FALSE;
END_IF;
Step 3 — Configure the HMI Tags
In WinCC (Comfort/Professional or WinCC Unified):
- Create four HMI tags of type WString with length 64 mapped to the four server STRING tags.
- Create an HMI tag of type UInt for Mode; set the property to read/write and limit input range to 0..2.
- Create a TIME tag with format Time for Interval; limit to 1 s .. 86400 s (WinCC auto-converts to T#..).
- Add an IO field with the "Apply" property driving
HMI_Cmd_NTP_Applyas a momentary pushbutton (SetBitWhileKeyPressed).
Step 4 — Trigger the Apply from the VISU
Press the "Apply NTP settings" button on the HMI. HMI_Cmd_NTP_Apply goes high for one PLC cycle. The block executes with the current STRING contents. Verify on the HMI that Status displays 16#0000 within a few hundred milliseconds and Error stays FALSE.
Step 5 — Confirm the CPU Actually Uses the New Server
Open TIA Portal online > CPU > Diagnostics > Time. The active NTP server is listed under "Time-of-day synchronization > NTP server". Alternatively, read the diagnostic buffer (online > CPU > Diagnostics > Diagnostics buffer) and look for event ID 0xE505 "Time was set via NTP" — the source address in the entry confirms the server that supplied the time.
Parameter Mapping Table (PLC ↔ HMI)
| PLC Tag (DB_NTP_Config) | Data Type | HMI Tag Name | HMI I/O Field Property |
|---|---|---|---|
| Server1_IP | STRING[64] | HMI_NTP_Server1 | WString, 64 chars, Input/Output |
| Server2_IP | STRING[64] | HMI_NTP_Server2 | WString, 64 chars, Input/Output |
| Interval | TIME | HMI_NTP_Interval | Time, ms resolution, range 10 s..24 h |
| Mode | UINT | HMI_NTP_Mode | UInt, fixed value 2 (set via hidden dropdown) |
| Req | BOOL | HMI_Cmd_NTP_Apply | Bool, momentary pushbutton |
| Status | WORD | HMI_NTP_Status | Hex display, output only |
| Error | BOOL | HMI_NTP_Error | Bool, output, alarm trigger |
Verification Checklist
- [ ] STATUS = 16#0000 after REQ edge returns to FALSE.
- [ ] DONE = TRUE for at least one PLC cycle.
- [ ] BUSY = FALSE after DONE.
- [ ] ERROR = FALSE.
- [ ] CPU online > Diagnostics > Time > NTP server shows the new IP address.
- [ ] CPU diagnostic buffer contains event "Time was set via NTP" within one interval period.
- [ ] Disconnect the old NTP server (block its port 123/UDP at the switch) and confirm time sync continues from the new server.
Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| DONE=TRUE, STATUS=0000, but CPU still uses old server. | Engineering config was never downloaded; IF_CONF_NTP wrote to empty slot. | Download project once with NTP mode enabled, then use MODE=2. |
| STATUS=8081, error "Invalid IP format". | HMI sent STRING with trailing characters or wrong length. | Match STRING length on HMI and PLC; trim whitespace in HMI script before write. |
| STATUS=8080, "MODE not supported". | CPU firmware older than V2.1. | Update CPU firmware or use MODE=1 (overwrite). |
| STATUS=8090, "No NTP configuration present". | NTP mode disabled in device properties. | Enable NTP mode in CPU properties, download, then use MODE=2. |
| STATUS=80A1, "Resource locked". | TIA Portal online connection active. | Go offline or disconnect the programming device before issuing REQ. |
| Block never raises BUSY, REQ stays TRUE. | REQ is being held continuously (level-triggered). | Use edge detection or a momentary button; reset REQ after DONE/ERROR. |
| Block raises BUSY forever, never DONE/ERROR. | CPU in STOP or system data locked. | Verify CPU is RUN; check for active online force on NTP config tags. |
| Server IP changes but time offset grows. | NTP server unreachable on PROFINET interface. | Verify route, firewall, port UDP/123 open from PLC to NTP. |
Edge Cases and Field-Proven Notes
No CPU restart required. The new NTP server becomes active immediately after DONE. The first successful synchronization is performed on the next interval tick.
Failover behaviour. If SERVER_1_IP is reachable, the CPU uses it exclusively. Servers 2..4 are tried in order only if the previous one stops responding. Configure at least two servers for redundancy in production cells.
STRING encoding on TIA Portal <V16. Older TIA Portal versions handle STRING differently in optimised data blocks. If the block reports STATUS=8081 on first write after download, compile the project and re-download the program — STRING headers are sometimes stale until a full recompile.
WinCC Unified vs. Comfort. WinCC Unified uses WSTRING (UTF-16). IF_CONF_NTP expects STRING (UTF-8 ASCII). Configure the HMI tag as STRING with conversion or use a script that copies WSTRING → STRING byte by byte before write.
Security note. NTP traffic is unauthenticated by default. On a machine cell with PROFINET only, isolation from the office LAN is sufficient. On converged networks, configure firewall ACLs to restrict UDP/123 to the NTP server only.
Related Configuration: Enable NTP Mode in TIA Portal
Before IF_CONF_NTP can modify anything, NTP must be enabled in the device configuration:
- Open the CPU device view in TIA Portal.
- Navigate to Properties > Time of day > Time synchronization.
- Set NTP mode to "NTP server (RFC 5905)" or "Secure NTP (RFC 5905 with authentication)" if your server supports key-based authentication.
- Enter the engineering-time NTP server IP (used as initial value before runtime modification).
- Compile and download the project to the CPU.
The S7-1500 system manual, available on the Siemens support portal, documents the supported NTP modes and authentication keys in chapter "Time synchronization".
FAQ
Why does IF_CONF_NTP return DONE=TRUE but the CPU keeps using the original NTP server?
The most common reason is that MODE is set to 0 (read) instead of 2 (modify). MODE=0 returns the current configuration but never writes. Set MODE := 2, re-trigger REQ with a rising edge, and confirm STATUS = 16#0000.
Do I need to restart the CPU or HMI after changing the NTP server IP from the HMI?
No. IF_CONF_NTP applies the new configuration immediately. The first synchronization on the new server occurs at the next interval tick (default 60 s). You can verify without restart via online > Diagnostics > Time.
What does STATUS = 16#8081 mean and how do I fix it?
STATUS 16#8081 indicates an invalid IP format. This usually means the HMI wrote a STRING shorter or longer than expected (for example, a 15-character buffer for a 16-character "192.168.100.250" address). Match the PLC STRING length (64) to the HMI tag length and strip any trailing spaces or carriage returns.
Can IF_CONF_NTP enable or disable NTP mode entirely?
No. IF_CONF_NTP only modifies the IP addresses, interval, and existing server list when NTP is already enabled. To enable or disable NTP mode, change the CPU device properties in TIA Portal and download the project.
How many NTP servers can the S7-1500 CPU use at once?
Up to four. IF_CONF_NTP exposes SERVER_1_IP through SERVER_4_IP. Servers are queried in numerical order until one responds. Empty strings disable individual slots.
Is IF_CONF_NTP available on S7-1200 CPUs?
No. The IF_CONF_NTP block is provided for the S7-1500 family only. On S7-1200 the NTP server IP is configured exclusively through the device properties in TIA Portal; runtime modification from the user program is not supported.