STEP7 - STRUCT members on non-word boundaries?


Thread Starter

Thomas Hergenhahn

Dear all,

STEP7 offers the possibility, do structure data blocks by means of STRUCTs or user defined datatypes.

I receive data from a Profibus slave that has the following structure:

BYTE state1
WORD value1
BYTE state2
WORD value2

It is no problem to read the 1st state using L DBB 0 and the 1st value using L DBW 1. But for the sake of documentation (symbols, comments) I should like to declare this structure in the data block.
If I try to do so and after declaring the first BYTE member, Step7 (V 5.0, service pack 2) insists on placing the next member at address 2.
Am I doing something wrong?

Daniel Chartier

Hello Thomas;

You are doing nothing wrong; data structures in S7-300/400 PLCs are on word boundaries (every 2 bytes) so you will have to use dummies (empty bytes) if you want to fill out the structure.

However, I don't think that matters much; if your slave is mapped as usual, the bytes and words are sent to an input or output address of the processor (IBx or QWx); you can then MOVE these values to any address in the DB you wish to fill. Of course, if you give us more info on the hardware you are planning to use, we might be able to find more details for you.

Hope this helps,
Daniel Chartier

Michael Griffin

If I recall correctly, the elements must start on word boundries:

BYTE state1 - Word 0,
WORD value1 - Word 1,
BYTE state2 - Word 2,
WORD value2 - Word 3

I've used UDTs with mixtures of bytes and words, and didn't have any problems. Have you tried creating a dummy byte to fill the hole between the state byte and the value word? E.g.

BYTE state1 - Word 0 (MSB),
BYTE dummy1 - Word 0 (LSB),
WORD value1 - Word 1,
BYTE state2 - Word 2 (MSB),
BYTE dummy2 - Word 2 (LSB),
WORD value2 - Word 3

While this theoretically shouldn't make a difference, it is possible that Step-7 is allocating enough room for a double word when you leave an undefined memory "hole".


Michael Griffin
London, Ont. Canada

Donald Pittendrigh

Perhaps using an array of 2 bytes instead of the word may solve the problem.

Be careful that your interpretation of the Profibus data map is correct, it is most unusual for a Profibus device to have data "boundaries" on uneven byte (start)