Learning Siemens S7-300 PLC Programming Beginner's Technical

David Krause15 min read
PLC HardwareSiemensTutorial / 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

Learning Siemens S7-300 PLC Programming: Beginner's Technical Guide

The SIMATIC S7-300 remains one of the most widely deployed PLC platforms in factory automation, process plants, and machine building. Engineers entering industrial automation frequently inherit S7-300 systems or maintain brownfield installations, and a structured learning path is essential to become productive. This guide consolidates the official Siemens learning track, the hardware that a beginner must understand, the software tools (STEP 7 V5.5 versus TIA Portal), and the first projects you should build to become a competent S7-300 programmer.

1. PLC Fundamentals: What an S7-300 Actually Does

A Programmable Logic Controller (PLC) is an industrial computer with ruggedized inputs and outputs that monitors field devices and executes control logic deterministically. The S7-300 is a modular mid-range PLC: a backplane (rail), a CPU, signal modules (SM), function modules (FM), communication processors (CP), and a power supply (PS) snap together to form a station. The CPU scans inputs, executes the user program OB/FB/FC/DB blocks, and writes outputs in a cyclic pattern with a configurable minimum cycle time.

Core concept: The S7-300 is a cyclic system. The CPU repeats: read inputs (PI/PII) → execute OB1 in chunks under the configured scan time → write outputs (PQ/PIQ) → run lower-priority OBs (OB35, OB82, OB100, OB121) as scheduled. Understanding the priority/time slice model is the first step away from beginner-level thinking.

2. S7-300 System Architecture

An S7-300 station is built on a DIN rail with the following slot order:

Slot Module Function
1 PS 305/307 Power Supply (24 V DC or 120/230 V AC input)
2 CPU 31x or CPU 31xC Processor with integrated I/O on C variants
3 IM 360/361/365 Interface Module for multi-rack expansion
4–11 SM/FM/CP Signal, Function, or Communication modules (max 8 per rack)

The CPU is the only mandatory module besides the PS. Every other module is optional. CPU 31xC variants (e.g., 312C, 313C, 314C, 315-2 PN/DP, 317-2 PN/DP, 319-3 PN/DP) integrate digital I/O, analog I/O (where applicable), and technology functions (counting, PID, positioning) on the CPU itself.

Decision path: For training, a CPU 314C-2 PN/DP or 315-2 PN/DP is the most cost-effective choice because it provides on-board digital I/O, analog inputs, PROFINET, and PROFIBUS, eliminating the need for separate SMs during the first year of learning. Verify the catalog number and firmware version on the module's front label before ordering.

3. CPU 31x Family Reference

The S7-300 CPU line evolved over three decades. Choosing a target CPU for self-training matters because some instructions and organization blocks differ across versions.

CPU Class Typical Use Notes for Learners
CPU 312 / 312C Small machines Limited work memory; suitable only for very small programs
CPU 313 / 313C Compact machines Entry point with 128 KB work memory, MPI
CPU 314 / 314C Standard mid-size Recommended for first training bench; on-board I/O on 314C
CPU 315-2 DP / PN/DP Mid-range with fieldbus Most popular for training; PROFINET + PROFIBUS
CPU 317-2 PN/DP High-performance Larger programs, faster bit execution
CPU 319-3 PN/DP Top of line Multi-CPU, large programs; rarely used in training

For exact specifications — bit execution time, number of flags, count of S7 timers/counters, supported OBs, and integrated I/O counts — refer to the device-specific manual on Siemens Industry Online Support. Search by CPU order number (e.g., 6ES7315-2EH14-0AB0) to retrieve the matching datasheet.

4. Software Tools: STEP 7 V5.5 vs TIA Portal

This is the single most important decision a new S7-300 programmer must make, and the choice is usually driven by what is installed on the engineering workstation you will use.

4.1 STEP 7 V5.5 (Simatic Manager, "Classic")

STEP 7 V5.5 is the traditional tool for S7-300/S7-400. It uses the Simatic Manager (the classic project tree), supports S7-300, S7-400, ET 200, and WinCC flexible 2008. It does not natively support S7-1200/S7-1500. STEP 7 V5.5 is at end of life but is still the only choice for older installations and is therefore critical for maintenance engineers.

4.2 TIA Portal (STEP 7 in the TIA Portal)

TIA Portal unifies STEP 7, WinCC, Startdrive, and Safety Integrated into a single engineering environment. For the S7-300, TIA Portal supports the CPU 31x with the appropriate GSD/device package. The portal-based project tree, the integrated HMI engineering, and the modern PLC tag model make TIA Portal the recommended choice for new development.

Criterion STEP 7 V5.5 (Classic) TIA Portal
Project tree Simatic Manager, hierarchical S7/M7/HMI Portal view (tasks) + Project view (objects)
Programming editors LAD, FBD, STL, SCL, S7-GRAPH, HiGraph LAD, FBD, SCL, GRAPH; STL is read-only (legacy)
Online diagnostics Modular diagnostic screens Integrated online/diagnostics, trace, web server
Hardware catalog HW Config (insert from catalog) Device view with drag-and-drop
Compiling Per program/section Whole-station compile with consistency check
Best for Legacy maintenance, S7-400 projects New projects, mixed S7-300/1200/1500 fleets

Recommendation: if you are learning S7-300 from scratch and the company uses TIA Portal, start in TIA Portal. If you are maintaining brownfield S7-300 systems installed before 2010, learn Simatic Manager first.

5. Programming Languages in the S7-300

STEP 7 supports five standard languages defined in IEC 61131-3 plus S7-GRAPH (sequential control):

  • LAD (Ladder Diagram) — Contact-and-coil representation. Default for electricians transitioning to PLCs.
  • FBD (Function Block Diagram) — Boolean function blocks. Preferred for complex interlocks.
  • STL (Statement List) — Mnemonic text. Available only in STEP 7 V5.5 as a writable language. TIA Portal treats STL as a read-only legacy view. STL is required for optimizing time-critical loops.
  • SCL (Structured Control Language) — Pascal-like, IEC 61131-3 ST. Best for data handling, math, loops, and reusable FBs.
  • S7-GRAPH — Sequential function chart for step/transition state machines. Optional package.

5.1 Ladder Example: Start/Stop with Seal-in

Network 1: Motor start seal-in
      |  I 0.0    I 0.1    Q 4.0     |
  ---| |------|/|------+---( )------|
      |  Start   Stop    Motor      |

Bit I 0.0 = start pushbutton (NO), I 0.1 = stop pushbutton (NC), Q 4.0 = motor contactor output. Q 4.0 is its own seal-in contact.

5.2 SCL Example: Scaling a 4–20 mA Analog Input

// IW 256 = raw input (0–27648 = 0–20 mA on most S7-300 SMs)
// Scale to engineering units 0.0–100.0 %
IF IW256 < 0 THEN IW256 := 0; END_IF;
IF IW256 > 27648 THEN IW256 := 27648; END_IF;
rScale := (INT_TO_REAL(IW256) / 27648.0) * 100.0;

6. Project Structure: Blocks and Organization

S7-300 user programs are organized into blocks. Every project uses the same taxonomy:

Block Type Name Range Purpose
OB — Organization Block OB1, OB10, OB35, OB40, OB82, OB100, OB121, OB122 Cyclic, time-of-day, cyclic interrupt, error, startup, fault
FB — Function Block FB1–FB65535 Reusable code with instance DB
FC — Function FC0–FC65535 Reusable code without memory (or with TEMP/STAT)
DB — Data Block DB1–DB65535 Instance data or shared global data
SDB — System Data Block Auto-generated Hardware configuration, communication links
UDT — User-Defined Type UDT0–UDT65535 Custom data structures

OB1 is the main cyclic block executed each scan. Startup OB100 (warm restart) and OB101 (hot restart) run once on power-up. OB82 handles diagnostic interrupts (wire break on an analog input, for example). OB121/OB122 are programming or I/O access errors — if they are not programmed the CPU goes STOP.

7. Building Your First S7-300 Training Bench

7.1 Hardware Prerequisites

  1. One S7-300 CPU (used or new) — 314C-2 PN/DP or 315-2 PN/DP recommended.
  2. One SIMATIC S7-300 rail, 530 mm or 830 mm.
  3. One PS 307 (24 V DC, 5 A or 10 A).
  4. One SM 321 (DI 16x24VDC) and one SM 322 (DO 16x24VDC) for bench wiring, unless using a CPU with integrated I/O.
  5. One Ethernet cable (for PROFINET variants) and one MPI/DP programming cable if MPI is used.
  6. 24 V DC power supply for the inputs and outputs (separate from the PS 307 if you want isolated rails).
  7. A few pushbuttons, a selector switch, and indicator lamps wired to a terminal block.

7.2 Software Prerequisites

  1. STEP 7 V5.5 SPx or TIA Portal V16/V17/V18 with the S7-300 device package installed. Confirm the TIA Portal version supports your CPU by opening the hardware catalog in the device view.
  2. PLCSIM (bundled with STEP 7) for offline simulation if no physical CPU is available.
  3. Siemens SCE learning modules (PDF and video). Access via the official Siemens Automation Cooperates with Education (SCE) site.

8. Step-by-Step: Your First Project in TIA Portal

8.1 Create a Project

  1. Open TIA Portal. In the Portal view click Create new project.
  2. Name the project (e.g., S7300_FirstProject) and set the project path.
  3. Click Configure a device → Add new device → SIMATIC S7-300 → select your CPU (e.g., CPU 314C-2 PN/DP, 6ES7314-6EH04-0AB0). Confirm with Add.

8.2 Configure the Hardware

  1. The device view opens with the rail and the CPU in slot 2. Drag a PS 307 to slot 1.
  2. Add a SM 321 (DI 16x24VDC) to slot 4 and a SM 322 (DO 16x24VDC) to slot 5 from the hardware catalog.
  3. Open the CPU properties → PROFINET interface [X1] → Ethernet addresses. Set the IP address (e.g., 192.168.0.10) and subnet mask.
  4. Compile and download the hardware configuration to the CPU.

8.3 Write the First Program

  1. Open Program blocks → double-click Main [OB1].
  2. Drag a NO contact onto Network 1. In the operand field type %I0.0 (TIA Portal syntax) for the first digital input on the CPU's integrated I/O, or %I4.0 if the input is on the SM 321 in slot 4.
  3. Add a NC contact with operand %I0.1.
  4. Add a coil with operand %Q4.0. Add another NO contact in parallel to the start input referencing the same output to implement the seal-in.
  5. Compile the block (Ctrl+B). Download to the CPU. Toggle Monitor on/off to see the contact and coil state in real time.

8.4 Verify

  • Press the start pushbutton wired to I 0.0 — the output Q 4.0 should latch even after release.
  • Press the stop pushbutton wired to I 0.1 — the output should drop.
  • In Online & Diagnostics check the CPU operating mode (RUN/STOP) and the scan cycle time.

9. Step-by-Step: Your First Project in STEP 7 V5.5

  1. Launch Simatic Manager. File → New → name the project.
  2. Insert a SIMATIC 300 Station in the project.
  3. Open HW Config, drag the rail, the PS 307, the CPU, and the SMs into the slots from the hardware catalog.
  4. Configure the MPI or PROFINET interface of the CPU with the correct address.
  5. Save and compile (Station → Save and Compile). Download to the target CPU.
  6. In the S7 Program / Blocks folder, double-click OB1 to open the LAD/FBD/STL editor. Build the same seal-in circuit described in Section 8.
  7. Download the blocks (PLC → Download). Click the Monitor glasses icon to view live status.

10. Practice Project Roadmap

Work through these projects in order. Each one introduces a new concept while reinforcing the previous lesson.

# Project Concepts Learned
1 Start/Stop motor with seal-in Bit logic, scan cycle, monitor online
2 Two-hand anti-repeat (jog) Edge detection, set/reset flip-flop
3 Traffic light controller On-delay (SD) and off-delay (SF) timers, sequence control
4 Conveyor with parts counter Up/down counters (CTU/CTD/SC), retentive flags
5 Tank level with analog input Analog scaling, FC parameter passing
6 Reusable valve block in FB with instance DB FB/DB concept, multi-instance DB
7 Sequential batch process with S7-GRAPH Step/transition, interlocks, manual mode
8 PID temperature control FB 58 / PID_CP from library, autotuning
9 PROFINET ET 200S remote I/O Distributed I/O, device name assignment
10 HMI tag integration WinCC in TIA Portal, alarms, screen navigation

11. Common Beginner Errors and How to Avoid Them

Symptom Likely Cause Fix
CPU stays in STOP after download OB121/OB122 not programmed, syntax error in OB1 Read the diagnostic buffer (Online → Diagnostics → Diagnostic Buffer). Fix the listed block and OB number.
SF (System Fault) LED on Hardware error — wrong module, wire break, missing 24 V Open Online → Diagnostics; check module status.
BF (Bus Fault) LED on PROFINET port No device name assigned to the IO device Use TIA Portal → Online → Accessible devices → Assign PROFINET device name.
Inputs read 0 even though 24 V is present Input group missing 24 V reference; sensor sink/source mismatch Verify the PS 307 output and the SM 321 sensor supply terminals; confirm Type 1 (P-reading) sensor compatibility.
Outputs do not switch CPU in STOP, or output overload (FWD/BF LED) Check CPU mode; measure current per channel against the SM 322 rating.
Online monitor shows no contact state Wrong PLC selected, or firewall blocking PG/PC interface Confirm the PG/PC interface in the Set PG/PC Interface dialog; set the same subnet as the CPU.
Safety reminder: Always connect the CPU and modules on a fully isolated lab supply. The first time you power the rack, do so with a current-limited bench supply and check for reverse polarity or short circuits before the protection trips. Industrial cabinets must be wired in accordance with the local electrical code, and emergency stop circuits must be hardwired — never implemented only in software.

12. Official Siemens Learning Resources

Use only official Siemens materials. The SCE (Siemens Automation Cooperates with Education) program publishes free modular curricula aimed at universities, vocational schools, and self-learners. The modules are versioned for TIA Portal and for the classic Simatic Manager. Always download the most recent PDF set; module numbers and exercise files change as the toolchain evolves.

13. Recommended Study Sequence (12 Weeks)

  1. Weeks 1–2: Read the SCE "PLC basics" module. Build the training bench. Run the seal-in example.
  2. Weeks 3–4: Complete the bit logic and timer modules. Do projects 1–3 above.
  3. Weeks 5–6: Counters, edge evaluation, and the SCE module on counters. Do project 4.
  4. Weeks 7–8: Analog value processing module. Do project 5. Read the manual section on wiring analog sensors.
  5. Weeks 9–10: FBs, instance DBs, and multi-instance. Do project 6. Begin S7-GRAPH project 7.
  6. Week 11: Communication — MPI, PROFIBUS, PROFINET. Configure an ET 200S (project 9).
  7. Week 12: HMI integration and PID control. Document your projects and review.

14. Working Code: A Reusable Valve FB in SCL

FUNCTION_BLOCK ValveControl
VAR_INPUT
  bOpenCmd   : BOOL;   // open request
  bCloseCmd  : BOOL;   // close request
  bOpnPerm   : BOOL;   // open permission (interlock chain OK)
  bClsPerm   : BOOL;   // close permission
  bOpnFbk    : BOOL;   // open limit switch
  bClsFbk    : BOOL;   // close limit switch
  tMonTime   : TIME;   // max time to reach end position
END_VAR
VAR_OUTPUT
  bOpnOut    : BOOL;   // open command to actuator
  bClsOut    : BOOL;   // close command to actuator
  bFault     : BOOL;   // motion time-out fault
END_VAR
VAR
  tonMon     : TON;    // motion watchdog
  xState     : INT;    // 0=idle, 1=opening, 2=closing
END_VAR
BEGIN
  // Interlocks
  IF NOT bOpnPerm THEN bOpenCmd := FALSE; END_IF;
  IF NOT bClsPerm THEN bCloseCmd := FALSE; END_IF;

  // Outputs (interlock both coils off before toggling)
  bOpnOut := FALSE;
  bClsOut := FALSE;

  CASE xState OF
    0:  // idle — wait for a command
      IF bOpenCmd AND NOT bCloseCmd THEN xState := 1; tonMon(IN := FALSE); END_IF;
      IF bCloseCmd AND NOT bOpenCmd THEN xState := 2; tonMon(IN := FALSE); END_IF;

    1:  // opening
      bOpnOut := TRUE;
      tonMon(IN := TRUE, PT := tMonTime);
      IF bOpnFbk THEN xState := 0; END_IF;
      IF tonMon.Q THEN bFault := TRUE; xState := 0; END_IF;

    2:  // closing
      bClsOut := TRUE;
      tonMon(IN := TRUE, PT := tMonTime);
      IF bClsFbk THEN xState := 0; END_IF;
      IF tonMon.Q THEN bFault := TRUE; xState := 0; END_IF;
  END_CASE;

  // Clear fault on rising edge of both feedbacks (manual reset)
  IF bFault AND bOpnFbk AND bClsFbk THEN bFault := FALSE; END_IF;
END_FUNCTION_BLOCK

This FB pattern — one FB per field device with its own instance DB — scales to thousands of devices and is the standard Siemens programming style for skid and process plants.

15. Verification Checklist Before Going Live

  • Hardware configuration compiled without errors; SDB matches the actual rack.
  • All FC/FB/DB blocks are downloaded (not only the changed ones).
  • Watchdog and OB121/OB122 are written if any I/O access can be invalid.
  • Retentive flags, timers, and counters are mapped to the correct retentive areas in the CPU properties.
  • PROFINET device names are assigned and the topology is downloaded.
  • Emergency stop is hardwired; software E-stop is supplementary only.
  • CPU scan time is below 70% of the configured maximum cycle time to leave headroom.
  • Documentation: each block has a header with version, author, and a brief description of inputs/outputs.

FAQ

Should a beginner learn STEP 7 V5.5 first or jump straight into TIA Portal?

If the plant you support is older brownfield, start in STEP 7 V5.5 (Simatic Manager) — many S7-300 stations installed before 2010 are still maintained with this tool and STL is only writable there. If the company uses TIA Portal, start there. The logic concepts are identical; the editors differ.

Can I learn the S7-300 without buying hardware?

Yes. Use PLCSIM (bundled with STEP 7 or TIA Portal) to simulate the CPU. You can develop, download, monitor, and force I/O against PLCSIM. For PROFINET and most fieldbus, S7-PLCSIM with the NetToPLCSIM tunneler lets a real ET 200 talk to the simulated CPU.

What is the most cost-effective CPU for a personal S7-300 training bench?

A used CPU 314C-2 PN/DP or CPU 315-2 PN/DP is the typical choice. The 314C has integrated 24 DI / 16 DO / 4+1 AI / 2 AO, plus a PROFINET and a PROFIBUS port, which removes the need to buy extra SMs while you are still learning. Verify the exact order number and firmware version on the Siemens Industry Online Support datasheet before purchase.

Why does the CPU go to STOP with the SF LED on after I download my program?

The diagnostic buffer (Online → Diagnostics → Diagnostic Buffer) lists the OB that triggered the stop. In most beginner programs it is OB121 (programming error) caused by accessing a non-existent DB, or OB122 (I/O access error) caused by referencing an I/O address that is not configured. Read the buffer, fix the block, and cycle the CPU to RUN.

How do I make timers and counters retentive across power cycles?

Open the CPU properties in HW Config (STEP 7 V5.5) or the device configuration (TIA Portal), go to Retentive Memory / Retentivity, and enter the number of retentive MB, S7 timers, and S7 counters. The values entered must not exceed the CPU's maximum. Anything not covered by the retentive range is reset on power-off or STOP→RUN transition.

Back to blog