05 — READING COILS (FC1)

How FC1 packs bits into bytes, LSB-first.

Estimated 7 minutes.

FC1 reads bits, in bulk.

Function code 1 reads up to 2000 coils in a single request. Coils are bits — on or off — and the response packs them densely into bytes to keep the message short.

The request.

Function (1 byte) + starting address (2 bytes) + quantity (2 bytes).

The response carries a byte count then the bits.

The slave does not say "here are 12 bits" directly. It says "here are 2 bytes" and you unpack the bits yourself. That keeps the framing simple — every byte after the count is just data.

The response.

Function + byte count + N bytes of packed bits.

Packing rule: LSB first within each byte.

Coil 0 → bit 0 of byte 0 (the least significant bit). Coil 1 → bit 1 of byte 0. Coil 7 → bit 7 of byte 0. Coil 8 → bit 0 of byte 1. Bit-numbered like a little-endian byte.

12 coils → 2 bytes.

The first 8 coils fill byte 0; the next 4 fill the bottom of byte 1; the top of byte 1 is padding.

Coil packing.

Toggle the 16 coils on the left. The right pane shows the exact 2 bytes the slave would send.

Read 1 coil.

You request FC1, quantity = 1. How many data bytes are in the response?

  • 0
  • 1
  • 2

Read 9 coils.

You request 9 coils. How many data bytes are in the response?

  • 1
  • 2
  • 9

Padding bits — ignore.

When the requested quantity is not a multiple of 8, the top bits of the last byte are whatever the slave felt like setting (usually 0). Always mask off the bits you did not ask for.

You can decode an FC1 response.

  • FC1 reads up to 2000 coils per request.
  • Response = function + byte count + N bytes.
  • Bits packed LSB-first per byte; coil 8 = bit 0 of byte 1.
  • Ignore the padding bits in the final byte.

Lesson 05 complete.

  • You can build an FC1 request from address + quantity.
  • You can decode the response bytes back into coil states.
  • You know to mask off padding bits in the last byte.