Creating Data Log Files on S7-1200 SD Card with TIA Portal

David Krause10 min read
S7-1200SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Overview

This reference describes how to implement persistent data logging on a SIMATIC S7-1200 CPU using the plug-in memory card (SMC, often referred to as the SD card slot on the CPU front cover). The implementation uses the DataLog instruction family inside TIA Portal to create, open, write, close, and delete CSV-format log files directly from user program execution.

On the S7-1200 platform, the term "log file" maps to the Siemens DataLog object: a sequential CSV record stored under \DataLogs\ on the memory card. DataLogCreate, DataLogOpen, DataLogWrite, DataLogClose, DataLogDelete, and DataLogNewFile are the six canonical instructions. They are documented in the S7-1200 System Manual, Chapter 4.5 "Memory concepts" and the TIA Portal Online Help topic "Data logs". The legacy entry point in the discussion points to the German-locale manual URL S7-1200 Programmable Controller System Manual (entry ID 109759420), which supersedes the older 36932465 entry.

Important distinction: The "Program Card" mode described in the S7-1200 manual Chapter 4.5.4 stores the user program on the SMC. Data logging is an independent capability that writes runtime data to CSV files on the same card. You do not have to switch the card to program mode to use DataLog instructions.

2. Prerequisites

Before configuring log files, verify the following hardware and software baseline:

  • CPU: SIMATIC S7-1200 (CPU 1211C, 1212C, 1214C, 1215C, 1217C, or 1212FC/1214FC/1215FC). All current firmware versions support DataLog. The instructions were introduced in firmware V2.0 with the first DataLog block set and expanded in V4.x with the circular-log and header enhancements.
  • Memory card: SIMATIC Memory Card (SMC). Siemens catalog numbers in the Siemens Industry Mall include 6ES7954-8LC02-0AA0 (2 MB), 6ES7954-8LE02-0AA0 (12 MB), 6ES7954-8LF02-0AA0 (4 MB), 6ES7954-8LL02-0AA0 (24 MB), and 6ES7954-8LP02-0AA0 (256 MB). The card must be formatted as FAT32; the SMC supplied by Siemens ships pre-formatted. Commercial SD cards (non-SMC) work in some CPUs but are not covered by Siemens warranty.
  • Engineering tool: TIA Portal V13 SP1 or later (V16/V17/V18 recommended for current firmware support). STEP 7 Basic in the matching version.
  • Insertion state: Insert the SMC into the CPU while the CPU is powered but stopped, or while unpowered. The CPU does not have to be in STOP for a DataLog workflow; it must be in STOP only if you are switching the card into Program Card mode.

3. S7-1200 Storage Model

The S7-1200 distinguishes three storage destinations for user data:

Storage Volatile? Use Instruction family
Work memory (load + work) Yes Active code, current DB values during RUN Standard load/transfer, MOVE
Retentive memory No (super-cap / battery backed) Persisted tags across power cycle Standard tags with RETAIN attribute
SIMATIC Memory Card (SMC) No Program archive, DataLog CSV files, recipes DataLogCreate / Write / Read / Close

DataLog files are written exclusively to the SMC under the path \DataLogs\. The directory is created automatically the first time a DataLogCreate call succeeds.

4. SMC Insertion and Verification

  1. Power the CPU. Open the front cover.
  2. Insert the SMC into the slot labeled SIMATIC MEMORY CARD with the label side facing you. Push until it clicks.
  3. \li>Observe the CPU's MAINT LED. A brief flash while the CPU enumerates the card is normal. A solid MAINT LED indicates a card error (wrong format, write-protect, or unsupported card).
  4. In TIA Portal, go online (Ctrl+K) and open Online & diagnostics > Memory. The card should appear with its free/total size reported.
  5. Confirm file system: open Project tree > PLC > Online > Files and verify the \DataLogs\ directory exists or is created on first write.
Caution: Removing the SMC while the CPU is writing can corrupt open DataLog files. Always call DataLogClose and check its DONE bit before ejecting, or stop the CPU first.

5. The DataLog Instruction Set

Six extended instructions make up the DataLog family. All are found in TIA Portal under Instructions > Extended instructions > Data logs.

Block Purpose Key inputs Key outputs
DataLogCreate Create a new CSV file with header row REQ, NAME (STRING), ID, HEADER (ARRAY), DATA (ARRAY), TIMESTAMP, FORMAT DONE, BUSY, ERROR, STATUS
DataLogOpen Open existing file for append REQ, NAME / MODE (APPEND/EMPTY) DONE, BUSY, ERROR, STATUS
DataLogWrite Append one record REQ, ID, WRITE_DATA (ARRAY of matching type) DONE, BUSY, ERROR, STATUS
DataLogClose Close handle and flush buffers REQ, ID DONE, BUSY, ERROR, STATUS
DataLogDelete Delete file from card REQ, NAME DONE, BUSY, ERROR, STATUS
DataLogNewFile Close current and open a fresh file (useful for daily rotation) REQ, ID, NAME DONE, BUSY, ERROR, STATUS

The STATUS output is a WORD returning a hex error code. Common values include:

STATUS (hex) Meaning Typical remedy
0000 No error —
7000 No job active (idle) Normal state; no action
80A1 Name invalid (illegal characters) Use only A–Z, 0–9, underscore
80A2 File already exists Use DataLogOpen with MODE=APPEND, or delete first
80A3 Card not present Insert SMC; verify MAINT LED
80A4 Card write-protected Slide the write-protect tab; use SMC without lock
80A7 Card full Delete old logs or rotate via DataLogNewFile
80B1 Header / data type mismatch on Write Align WRITE_DATA layout to HEADER declaration
80B2 Log full (10 MB limit per file) Use DataLogNewFile to roll a new file
80C3 Maximum open logs exceeded (≤10) Close unused DataLog IDs

The complete STATUS catalog is in the TIA Portal online help under "Data logs — error information" and in the S7-1200 System Manual entry at S7-1200 System Manual.

6. TIA Portal Project Configuration

  1. In the project tree, open PLC_1 > Program blocks and add a new FB or use an existing OB1 cycle.
  2. Create a global DB named DB_LogControl with the following structure:
    TYPE "DB_LogControl"
    VERSION : 0.1
      STRUCT
       LogID : DINT;              // handle returned by DataLogCreate
       LogName : STRING[20];      // e.g. 'ProcessLog'
       LogHeader : ARRAY[0..3] OF STRING[16];
       LogData   : ARRAY[0..3] OF REAL;
       CycleTrigger : BOOL;
       ErrorWord : WORD;
       ReadyFlag : BOOL;
      END_STRUCT;
    END_TYPE
  3. Add the DataLogCreate, DataLogOpen, DataLogWrite, and DataLogClose blocks to your program. Drag each from Instructions > Extended instructions > Data logs.
  4. Wire the blocks as shown in the next section.
  5. Compile (Ctrl+B) and download to the CPU (Ctrl+L).

7. Step-by-Step Ladder / STL Sequence

  1. First scan (OB1 startup or first-cycle flag): call DataLogCreate with NAME = "ProcessLog", ID assigned to DB_LogControl.LogID, HEADER containing the column titles, and TIMESTAMP enabled. Pulse REQ with a rising edge of FirstScan.
  2. On every successful create: latch ReadyFlag. If STATUS = 80A2 (already exists), fall through to DataLogOpen instead.
  3. Triggering write: in OB1 on a 1-second or 100-ms cyclic event (use a TON clock generator), call DataLogWrite with the current process values pre-loaded into WRITE_DATA.
  4. Shutdown: in OB100 (warm restart) and on a controlled stop request, call DataLogClose. Monitor the DONE bit before ejecting the card.

8. Reference Implementation (SCL)

The following structured-text snippet can be pasted into a new SCL block. It demonstrates the canonical Create-Open-Write-Close sequence referenced in the field report.

// FB_ProcessLogger - sample implementation
DATA_BLOCK "DB_ProcessLogger"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
NON_RETAIN
  STRUCT
   LogID       : DINT := 0;
   Header      : ARRAY[0..3] OF STRING[16];
   RowData     : ARRAY[0..3] OF REAL;
   InitDone    : BOOL;
   WriteEnable : BOOL;
   LastStatus  : WORD;
  END_STRUCT;
END_DATA_BLOCK

FUNCTION_BLOCK "FB_ProcessLogger"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR
  DataLogCreate_0   : DataLogCreate;
  DataLogOpen_0     : DataLogOpen;
  DataLogWrite_0    : DataLogWrite;
  DataLogClose_0    : DataLogClose;
  tonCycle           : TON;
END_VAR
BEGIN
  // ---- Initialize log on first scan ----
  IF NOT InitDone THEN
     Header[0] := 'Timestamp';
     Header[1] := 'Temp_C';
     Header[2] := 'Press_kPa';
     Header[3] := 'Flow_Lpm';
     DataLogCreate_0(REQ := TRUE,
                     NAME := 'ProcessLog',
                     ID  := LogID,
                     HEADER := Header,
                     DATA := RowData,
                     TIMESTAMP := TRUE,
                     FORMAT := 0,
                     DONE => InitDone,
                     BUSY => ,
                     ERROR => ,
                     STATUS => LastStatus);
  END_IF;

  // ---- Cycle write every 500 ms ----
  tonCycle(IN := NOT tonCycle.Q, PT := T#500ms);
  IF tonCycle.Q AND InitDone THEN
     // populate RowData from process tags here, e.g.
     RowData[1] := "DB_Process".Temp_C;
     RowData[2] := "DB_Process".Press_kPa;
     RowData[3] := "DB_Process".Flow_Lpm;
     DataLogWrite_0(REQ := TRUE,
                    ID  := LogID,
                    WRITE_DATA := RowData,
                    DONE => ,
                    BUSY => ,
                    ERROR => ,
                    STATUS => LastStatus);
  END_IF;

  // ---- Close on stop / shutdown ----
  IF "StopRequest" THEN
     DataLogClose_0(REQ := TRUE,
                    ID  := LogID,
                    DONE => ,
                    BUSY => ,
                    ERROR => ,
                    STATUS => LastStatus);
  END_IF;
END_FUNCTION_BLOCK

9. Retrieving the Log Files

Three official methods are documented:

  1. TIA Portal online browser: Online > Files > CardReader / SD card > \DataLogs\ProcessLog.csv. Right-click > Download to file system.
  2. CPU Web server: enable the Web server in Device configuration > Web server. From the standard page "File browser" navigate to the log directory and download via HTTP.
  3. FTP server (firmware V4.0+): the S7-1200 can serve as an FTP server when the Ethernet port is configured with FTP access rights. Use any FTP client pointed at ftp://<CPU-IP>/DataLogs/.
File-name note: When TIMESTAMP is enabled on DataLogCreate, the CPU embeds a numeric suffix; the actual on-card file looks like ProcessLog.csv (one file per DataLogCreate call). With DataLogNewFile you can rotate per day into ProcessLog_001.csv, _002.csv, etc.

10. Common Pitfalls and Field-Verified Fixes

Symptom Likely cause Resolution
STATUS = 80A3 immediately after first call SMC not seated Re-seat the card; verify MAINT LED behavior
STATUS = 80A1 NAME contains dashes, dots, or non-ASCII Use alphanumeric + underscore only
Log exists but is empty DataLogWrite never pulsed REQ Add an edge-triggered flag on REQ; REQ is level-triggered only on rising edge
Header row missing HEADER array dimension zeroed or wrong size HEADER length must equal number of columns
New data not appearing on reload Card was removed before DataLogClose finished Always wait for DONE before eject
File grows past 10 MB Per-file size cap reached Implement DataLogNewFile rotation
Logs vanish after power cycle Card was never inserted; logs wrote to internal buffer only Verify card presence in online diagnostics
STATUS = 80B1 on Write WRITE_DATA type changed since Create Keep ARRAY type and length identical to HEADER definition

11. Verification Procedure

  1. Force a single Write in online mode; confirm DONE within one scan.
  2. From Online > Files, refresh and open \DataLogs\ProcessLog.csv in Excel or Notepad++. The header row must match the strings you passed to DataLogCreate.
  3. Power-cycle the CPU. Re-open the same file. The records must still be present.
  4. Run a 24-hour soak at the intended cycle rate; check file size does not exceed the configured rotation threshold.
  5. Remove the SMC with the CPU in STOP; insert into a PC with a SIMATIC card reader (6ES7792-0AA00-0XA0) or compatible; confirm file readability.

12. Advanced Topics

Circular logging: by setting FORMAT = 1 and combining DataLogWrite with DataLogNewFile, you can implement bounded-size ring logs suitable for trend buffers.

Recipe integration: the same SMC holds recipes under \Recipes\. Both DataLog and Recipe blocks coexist; the only shared constraint is the 10-file open-handle limit.

Cross-platform readability: CSV is plain ASCII; LibreOffice, Excel, Python pandas.read_csv, and Node csv-parse consume it without preprocessing. Endianness is irrelevant because all numeric values are stored as ASCII text.

Firmware behavior: DataLog on firmware V2.x did not support TIMESTAMP columns. If migrating from V2 to V4, regenerate the log files because the on-disk header layout differs. The S7-1200 firmware update package is available through Siemens Industry Online Support under entry type "Firmware update".

Memory budget: each open DataLog handle consumes approximately 2 KB of work memory. With the documented limit of ten open handles per CPU, this is normally negligible on any S7-1200 variant.

Why does my DataLogCreate return STATUS 80A3 even though the SD card is inserted?

The card may not be fully seated, or the write-protect tab is engaged. Power down, re-seat the SMC firmly until it clicks, slide the write-protect switch off, and confirm the MAINT LED is not solid. Then re-run DataLogCreate.

How large can a single S7-1200 DataLog file become?

Each DataLog file is capped at approximately 10 MB on the S7-1200. When the limit is reached, STATUS 80B2 is returned on the next Write. Implement DataLogNewFile to rotate to a fresh file before the cap is reached.

Do I need to put the CPU in STOP to insert or remove the SIMATIC Memory Card?

No for routine DataLog operation; the card can be inserted while powered. However, you must call DataLogClose and wait for DONE before ejecting, otherwise the open file may be corrupted. Removing the card under power without a prior close is not supported by Siemens.

Can I use any commercial SD card instead of a Siemens SMC?

S7-1200 accepts FAT32-formatted SD/SDHC cards up to the capacity documented for the CPU family, but Siemens explicitly excludes non-SMC media from the warranty and from functional support. Use catalog-number SMC (e.g. 6ES7954-8LE02-0AA0) for guaranteed behavior.

What is the difference between the Program Card and the DataLog workflow?

Program Card mode (S7-1200 manual chapter 4.5.4) uses the SMC to store the user program and copy it into work memory on startup. DataLog uses the same physical card but writes CSV record files at runtime. The two are independent; you do not have to enable Program Card mode to use DataLog.

Back to blog