IMDHMIControls LibraryShop main store

Troubleshooting

Why FB_EcCoESdoWrite reports a Sync Master error in TwinCAT

PLC programming Published 5 min read

Short answer

FB_EcCoESdoWrite reports the activation error because the EtherCAT slave has no task assignment, not because the SDO write itself is wrong. Assign the slave to a task in the master's Sync Unit Assignment dialog, or link a PLC variable to the slave's DevState input, and read the block's own bError and nErrId after bBusy drops.

On this page
  1. Why TwinCAT asks for a Sync Master
  2. Two ways to give the slave a task
  3. Fix the error handling in the PLC code
  4. Worked example: write 16#AAAA to index 16#607A
  5. The decision for each case
  6. Questions asked

The SDO write itself is not the problem. FB_EcCoESdoWrite performs the SDO download on its own and never needs the object linked as process data. The activation error appears because the EtherCAT slave has no task assignment: no PLC task owns the device, so TwinCAT refuses to activate the configuration, and the block then fails when it runs. Fix the configuration first — assign the slave to a task in the master's Sync Unit Assignment dialog, or link a PLC variable to the slave's DevState input. Then fix the second fault in the example program, which tests a local bError that starts FALSE and so erases the block's real diagnostic in the same cycle it appears.

Why TwinCAT asks for a Sync Master #

Scanning found the slave and its ESI description, and the device shows under the master, but that only proves the configuration knows the device exists. Every EtherCAT device in the configuration needs a task that is responsible for its data exchange. When the slave sits in the configuration with no task linked to it, activation stops with the message that the device needs at least one Sync Master.

The function block does not satisfy that requirement. The documented job of FB_EcCoeSdoWrite is to write an object from the slave's object directory by means of an SDO download — an acyclic service through the master, unrelated to the cyclic task link that activation checks. CODESYS exposes the same kind of runtime CoE SDO access, and its configuration has its own requirements; the approach is described in the article on configuring CODESYS EtherCAT CoE runtime SDO access. In TwinCAT you clear the message in the device configuration, not in the PLC program.

Two ways to give the slave a task #

Pick whichever route fits the project; both were confirmed to clear the message.

  1. Double-click the EtherCAT master device in the configuration.
  2. Open the EtherCAT tab and click Sync Unit Assignment.
  3. Select the slave or terminal, then select your task under the forced sync unit tasks and apply.
  4. Activate the configuration and confirm the Sync Master message is gone.

The alternative is to link a variable from your PLC program to the device's DevState input. That link establishes the required device-to-task relationship, which is why it works where you might expect a parameter link to fail. Linking to plain InfoData does not work — it was tried and the message stayed. DevState is the input that counts.

Fix the error handling in the PLC code #

The second fault hides the first one's diagnostic. The faulty logic tests a local bError variable with IF NOT bError inside the IF NOT fbSdoWrite.bBusy branch. That local variable is FALSE from the moment the program starts, so the code always takes the success branch, assigns zero to its own error ID, and never copies the block's outputs. A real failure is erased before you ever see it.

The corrected pattern reads the block's own outputs after the busy phase ends. The block name and its inputs and outputs below are the documented TwinCAT interface; the surrounding variables are an illustrative example with declared types and initial values:

PROGRAM MAIN
VAR
    nValue   : UINT  := 16#AAAA;  // example payload, two bytes
    fbSdo    : FB_EcCoESdoWrite;  // documented TwinCAT block
    bExecute : BOOL  := FALSE;
    bWriteOk : BOOL  := FALSE;    // example result flag
    nErrId   : UDINT := 0;        // example diagnostic store
END_VAR

fbSdo(
    sNetId    := '5.76.204.148.1.1', // example AMS Net ID of the master
    nSlaveAddr:= 1001,               // example configured slave address
    nIndex    := 16#607A,            // example CoE object index
    nSubIndex := 0,                  // example subindex
    pSrcBuf   := ADR(nValue),
    cbBufLen  := SIZEOF(nValue),     // two bytes for a UINT
    bExecute  := bExecute);

IF NOT fbSdo.bBusy AND bExecute THEN
    bExecute := FALSE;
    IF fbSdo.bError THEN
        bWriteOk := FALSE;
        nErrId   := fbSdo.nErrId;    // preserve the block's error ID
    ELSE
        bWriteOk := TRUE;
        nErrId   := 0;
    END_IF
END_IF

The write begins on a rising edge of bExecute, so set it TRUE for one program cycle and let the block finish; when bBusy returns FALSE the result is in fbSdo.bError and fbSdo.nErrId. The extra second call with bExecute := FALSE in the faulty program adds nothing once the busy handling is correct.

One safety note: a CoE write lands in the slave's object directory directly, outside any interlock logic in your PLC program, so test command-style objects with the drive or axis disabled.

Worked example: write 16#AAAA to index 16#607A #

The values below are the example configuration from a real setup; your Net ID, slave address and object index come from your own project.

Input Example value Meaning
sNetId '5.76.204.148.1.1' AMS Net ID of the EtherCAT master
nSlaveAddr 1001 Configured EtherCAT slave address
nIndex 16#607A CoE object index (the CiA 402 target position object, in this example)
nSubIndex 0 Subindex of the object
pSrcBuf, cbBufLen ADR(nValue), SIZEOF(nValue) Address and two-byte length of the UINT payload
nValue 16#AAAA Value written to the object

The test that proves the result has two stages. First, activate the configuration: it must come up without the Sync Master message. Second, apply one rising edge to bExecute, wait until fbSdo.bBusy is FALSE, and read fbSdo.bError. FALSE means the SDO download completed and the object now holds 16#AAAA; TRUE means preserve fbSdo.nErrId and diagnose before writing again. Reading a slave's error state back into the PLC through mapped data follows the same discipline as the article on EL3314 status word error handling in TwinCAT PLCs.

The decision for each case #

  • Activation reports "device needs at least one Sync Master": assign the slave to a task in Sync Unit Assignment, or link a PLC variable to the DevState input. Do not bother linking InfoData; it does not establish the required relationship.
  • bExecute fires but the block reports an error and your error ID reads zero: stop testing the local flag and copy fbSdoWrite.bError and fbSdoWrite.nErrId after bBusy drops.
  • Both fixes in place and the write still fails: the remaining cause is at the object itself — an index, subindex, access direction or buffer length the slave's object dictionary does not accept — and fbSdoWrite.nErrId tells you which.

Questions asked

Does FB_EcCoESdoWrite need the object linked as process data?

No. The block performs an acyclic SDO download into the slave's object directory, so the value travels as a service rather than as cyclic process data. The configuration still needs a task assignment for the slave, which is a separate requirement. Check the object's index, subindex, access direction and data length in the slave's object dictionary before you write.

Does linking InfoData to the PLC work as a task assignment?

No. In the tested case, linking a PLC variable to the device's plain InfoData did not clear the missing Sync Master condition, while linking the same variable to the DevState input did. If the Sync Unit Assignment route is inconvenient, link your PLC variable to DevState, activate the configuration, and confirm the activation message is gone before triggering bExecute.

Why does my error ID stay zero after a failed SDO write?

The faulty logic tested a local bError variable, which is FALSE before the first write completes, so the code always took the success branch and set its own error ID to zero. Copy the block's outputs instead: after bBusy goes FALSE, read fbSdoWrite.bError, and copy fbSdoWrite.nErrId into your own diagnostic variable only when that output is TRUE.

What length does cbBufLen need?

It must match the length of the object you are writing: two bytes for a UINT payload such as the example value. If the buffer length does not match the object's declared size, or the index, subindex or access direction is wrong, the slave aborts the SDO download and the block reports the failure through its nErrId output.

Keep reading

  • Troubleshooting

    Why an EL6224 IO-Link sensor is not recognized on ctrlX CORE

    Your EL6224 is fine on EtherCAT; the sensor is not recognized because ctrlX WORKS does not import IODD files or the Beckhoff-specific mechanisms other tools use. Skip the device repository import and configure the EL6224 by hand: a CoE startup entry for the sensor's port, written on the Pre-Operational to Safe-Operational transition, and a UINT input PDO entry at the matching process data index.

    PLC programming

  • Troubleshooting

    Why MB_MASTER on an S7-1200 reports Modbus error 16#8188

    Error 16#8188 on an S7-1200 MB_MASTER is an operating-mode fault, not a serial link failure. Set MODE 1, DATA_ADDR 30001, a length of 32 and MB_ADDR 1 to read the slave's D000 through D01F block as input registers 30001 through 30032, and hold EN TRUE through the REQ pulse.

    PLC programming

  • Troubleshooting

    Why MELSECNET II data reads zeros after adding a Modbus card

    The zeros are not a network fault. The QJ71MB91 occupies 32 I/O points, and inserting it ahead of the MELSECNET II module moved that module's start I/O number, so the access code reads the wrong position. Diff the I/O assignment against the map from before the change, re-address the assignment so the MELSECNET II module sits at 0070, and update every instruction that targets it.

    PLC programming