RTOS & Firmware Stacks

Modbus RTU and RS-485 DE-turnaround testing in CI

Catch truncated last bytes from dropping RS-485 DE on TXE instead of TC before shipping industrial fieldbus firmware.

The most common RS-485 firmware bug clears the MAX3485 DE pin when the UART TXE (transmit buffer empty) flag fires instead of waiting for TC (transmission complete). The stop bit and final CRC byte get clipped off the wire.

CircuitTwin wires your MCU UART and DE GPIO through a half-duplex RS-485 transceiver twin (MAX3485), checking exact frame integrity, reflected CRC-16 and silent-interval framing in CI.

Modbus RTU faults verified in CI

Bug classRoot causeTwin check
Truncated CRC byteDE cleared on TXE instead of TCVirtual RS-485 peer logs CRC-16 failure
Wrong CRC byte orderTransmitting MSB first instead of LSB firstPeer rejects request with silent drop
Bus collisionMaster polls while slave still drives busRS-485 transceiver flags contention event

Local CLI workflow

Shell - run Modbus RTU RS-485 test suite
ct test run --json --junit results/modbus.xml tests/modbus-rtu.suite.yaml

Suite & fault configuration

tests/modbus-rtu.suite.yaml
version: 1
board: nucleo-f446re
firmware: build/modbus_slave.elf
tests:
  - name: read-holding-registers-and-bad-crc
    timeout_ms: 2000
    expect:
      console_contains: "MODBUS_FC03_OK"
      exit_code: 0

CI pipeline integration

.github/workflows/modbus-ci.yml
name: Modbus RTU Twin CI
on: [push, pull_request]
jobs:
  modbus:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: cmake --build build
      - uses: circuittwin/action@v1
        with:
          suite: tests/modbus-rtu.suite.yaml

Troubleshooting checklist

SymptomFix
Last byte of response missing on RS-485 busWait for USART_SR_TC (transmission complete) before pulling the MAX3485 DE pin low.
Slave ignores valid FC03 requestVerify CRC-16/Modbus low-byte-first wire order using the Embedded CRC Calculator.

Frequently asked questions

QuestionAnswer
Can CircuitTwin verify half-duplex RS-485 DE timing automatically?Yes. Board definitions support rs485_buses bound to transceiver twins like MAX3485 so premature DE de-assertion corrupts the wire frame just like real silicon.

Related boards & component twins

More in RTOS & Firmware Stacks