Validate Modbus RTU Frames With CRC Sixteen Checksums
Last updated: November 29, 2026
Quick Overview
Implement the CRC-16/MODBUS checksum, a function that appends it to a request payload in the correct byte order, and a validator that rejects corrupted frames read from a serial line.
Schneider Electric
November 29, 20260
0
0 solved
Implement the CRC-16/MODBUS checksum, a function that appends it to a request payload in the correct byte order, and a validator that rejects corrupted frames read from a serial line.
Modbus RTU is still how many Schneider meters, drives and Modicon PLCs talk over RS-485, and embedded or gateway engineers are expected to handle the framing details. The interviewer checks bit manipulation, byte order discipline and whether you can test against a known vector.
What the Interviewer Expects
- Initializes CRC to 0xFFFF and uses the reflected polynomial 0xA001
- Appends the CRC low byte first
- Validates by recomputing over all bytes except the last two
- Uses a known check value to test
- Mentions a table-driven version for speed on microcontrollers
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you build a 256-entry lookup table and why is it faster?
- How does the receiver detect the end of an RTU frame on the wire?
- What changes for Modbus TCP, which has no CRC?
- How would you write this in C for a device with 2 KB of RAM?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
CRC-16/MODBUS: width 16, polynomial 0x8005 processed in reflected form (0xA001), initial value 0xFFFF, no final XOR, bytes processed least significant bit first. The two CRC bytes go on the wire low b...
High-Level Design
XOR each byte into the low end of the register, then shift right eight times, XORing the polynomial whenever the bit shifted out was 1. Because the algorithm is reflected, we shift right instead of le...