Troubleshooting
Why FB_EcCoESdoWrite reports a Sync Master error in TwinCAT
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
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.
- Double-click the EtherCAT master device in the configuration.
- Open the EtherCAT tab and click Sync Unit Assignment.
- Select the slave or terminal, then select your task under the forced sync unit tasks and apply.
- 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.
bExecutefires but the block reports an error and your error ID reads zero: stop testing the local flag and copyfbSdoWrite.bErrorandfbSdoWrite.nErrIdafterbBusydrops.- 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.nErrIdtells 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.