Examples of Register Communication

BECKHOFF KL336x

 
BECKHOFF Fieldbus Components: Access from the User Program

Examples of Register Communication

In the examples, the numbering of the bytes is according to the description without Word-Alignment.

Example 1: Reading the Firmware Issue Status from Register 9 of a Terminal

Output Data
Byte 0: Control Byte Byte 1: DataOUT1, high byte Byte 2:  DataOUT1, low byte
0x89  (1000 1001bin) 0xXX 0xXX

Explanation:

  • Bit 0.7 set indicates register communication active.
  • Bit 0.6 not set indicates reading the register.
  • Bit 0.5 to Bit 0.0 indicates with 00 1001bin the register number 9.
  • The output data word (Byte 1 and Byte 2) has no function at the reading access. If you want to change a register, you have to write the desired value into the output data word.
Input Data (answer of the bus terminal)
Byte 0: Status Byte Byte 1: DataIN1, high byte Byte 2: DataIN1, low byte
0x89 0x33 0x41

Explanation:

  • The terminal returns the value of the Control Byte in the Status Byte, as an acknowledgement.
  • The terminal returns the Firmware Issue Status 0x3341 in ASCII code, in the input data word (Byte 1 and Byte 2). This has to be interpreted as ASCII code:
    - ASCII code 0x33 stands for the cipher 3
    - ASCII code
    0x41 stands for the letter A
    Therefore the firmware version is 3A.

Example 2: Writing to an user registers

Note At normal operation all user registers other than register 31are write protected.
In order to deactivate write protection, you have to write the password (0x1235) into register 31. Write protection is activated again by writing any value other than 0x1235
Note that some of the settings that can be made in registers only become active after the next power restart (power-off/power-on) of the terminal.

I. Writing the code word (0x1235) to Register 31

Output Data
Byte 0: Control Byte Byte 1: DataOUT1, high byte Byte 2:  DataOUT1, low byte
0xDF (1101 1111bin) 0x12 0x35

Explanation:

  • Bit 0.7 set indicates: register communication active.
  • Bit 0.6 set indicates: writing to the register.
  • Bit 0.5 to Bit 0.0 indicates with 00 1111bin the register number 31.
  • The output data word (Byte 1 und Byte 2) contains the code word (0x1235) to deactivate the write protection.
Input Data (answer of the bus terminal)
Byte 0: Status Byte Byte 1: DataIN1, high byte Byte 2: DataIN1, low byte
0x9F (1001 1111bin) 0xXX 0xXX

Explanation:

  • In the Status Byte, the terminal returns a value, that differs only at bit 0.6 from the value of the of the Control Byte.
  • The input data word (Byte 1 and Byte 2) has no function after the the writing access. Values that might be shown are not valid!

II. Reading Register 31 (verifying the set code word)

Output Data
Byte 0: Control Byte Byte 1: DataOUT1, high byte Byte 2:  DataOUT1, low byte
0x9F (1001 1111bin) 0xXX 0xXX

Explanation:

  • Bit 0.7 set indicates register communication active.
  • Bit 0.6 not set indicates reading the register.
  • Bit 0.5 to Bit 0.0 indicates with 00 1111bin the register number 31.
  • The output data word (Byte 1 and Byte 2) has no function at the reading access.
Input Data (answer of the bus terminal)
Byte 0: Status Byte Byte 1: DataIN1, high byte Byte 2: DataIN1, low byte
0x9F (1001 1111bin) 0x12 0x35

Explanation:

  • The terminal returns the value of the Control Byte in the Status Byte, as an acknowledgement.
  • The terminal returns the current value of the code word register in the input data word (Byte 1 and Byte 2).

III. Writing into Register 32 (changing the content of the feature register)

Output Data
Byte 0: Control Byte Byte 1: DataIN1, high byte Byte 2:  DataIN1, low byte
0xE0 (1110 0000bin) 0x00 0x02

Explanation:

  • Bit 0.7 set indicates register communication active.
  • Bit 0.6 set indicates: writing to the register
  • Bit 0.5 to Bit 0.0 indicates with 10 0000bin the register number 32.
  • The output data word (Byte 1 and Byte 2) contains the new value for the feature register.
    Attention The given value 0x0002 is only an example!

    The bits of the feature register change the properties of the terminal und and have different meanings, depending on the terminal type. Please check the description of the feature register of your terminal type (chapter register description) about the meanings of the bits in detail, before changing the values!

Input Data (answer of the bus terminal)
Byte 0: Status Byte Byte 1: DataIN1, high byte Byte 2: DataIN1, low byte
0xA0 (1010 0000bin) 0xXX 0xXX

Explanation:

  • In the Status Byte, the terminal returns a value, that differs only at bit 0.6 from the value of the of the Control Byte.
  • The input data word (Byte 1 and Byte 2) has no function after the the writing access. Values that might be shown are not valid!

IV. Reading Register 32 (verifying the changed feature register)

Output Data
Byte 0: Control Byte Byte 1: DataOUT1, high byte Byte 2:  DataOUT1, low byte
0xA0 (1010 0000bin) 0xXX 0xXX

Explanation:

  • Bit 0.7 set indicates register communication active.
  • Bit 0.6 not set indicates reading the register.
  • Bit 0.5 to Bit 0.0 indicates with 10 0000bin the register number 32.
  • The output data word (Byte 1 and Byte 2) has no function at the reading access.
Input Data (answer of the bus terminal)
Byte 0: Status Byte Byte 1: DataIN1, high byte Byte 2: DataIN1, low byte
0xA0 (1010 0000bin) 0x00 0x02

Explanation:

  • The terminal returns the value of the Control Byte in the Status Byte, as an acknowledgement.
  • The terminal returns the current value of the feature register in the input data word (Byte 1 and Byte 2).

V. Writing to Register 31 (setting the code word back)

Output Data
Byte 0: Control Byte Byte 1: DataOUT1, high byte Byte 2:  DataOUT1, low byte
0xDF (1101 1111bin) 0x00 0x00

Explanation:

  • Bit 0.7 set indicates register communication active.
  • Bit 0.6 set indicates: writing to the register.
  • Bit 0.5 to Bit 0.0 indicates with 00 1111bin the register number 31.
  • The output data word (Byte 1 und Byte 2) contains 0x0000 to activate the write protection again.
Input Data (answer of the bus terminal)
Byte 0: Status Byte Byte 1: DataIN1, high byte Byte 2: DataIN1, low byte
0x9F (1001 1111bin) 0xXX 0xXX

Explanation:

  • In the Status Byte, the terminal returns a value, that differs only at bit 0.6 from the value of the of the Control Byte.
  • The input data word (Byte 1 and Byte 2) has no function after the the writing access. Values that might be shown are not valid!