herunterladen
Keywords: CRC, CRC-7, cyclic redundancy check, industrial output, PLC, programmable logic controller, C
code, CRC generation, microprocessor, switch
APPLICATION NOTE 6002
CRC PROGRAMMING FOR THE MAX14900E
OCTAL, HIGH-SPEED INDUSTRIAL SWITCH
By: Mike van Scherrenburg
Abstract: The MAX14900E octal high-speed industrial switch is a high-performance, feature-rich switch
capable of delivering 15W nominal to each of 8 loads. A microprocessor-compatible serial peripheral
interface provides access to many advanced features. For added safety, a hardware cyclic redundancy
check (CRC) circuit optionally protects this SPI interface against bit errors. This application note provides
example C code implementing CRC generation and detection algorithms in the microprocessor.
Introduction
The MAX14900E is a high-performance, 8-channel industrial switch with a rich and advanced feature set. A
SPI interface allows a microcontroller to monitor and control most aspects of the MAX14900E. To enhance
robustness, a hardware CRC (cyclic redundancy check) circuit in the MAX14900E can optionally protect all
data between it and a microprocessor against bit errors.
However, enabling the CRC feature in the MAX14900E is not enough. The microprocessor must also
mplement the same CRC algorithm in software, both to append check bits to data being sent to the
MAX14900E, as well as to verify those being received from it. One way to accomplish this is to inspect the
data sheet, and use it to create custom firmware to implement the necessary CRC functionality.
A better approach would be to use the functions in this application note instead. These are written in C, and
should prove easy to port over to most any common microprocessor.
Choosing the Correct Sources
This application note provides six sets of C source code, each implementing a CRC generator and a CRC
checker. The MAX14900E communicates with a microprocessor using either single byte packets, or double
byte packets. Three of the code sets implement generator and checker algorithms for single byte packets,
whereas the other three code sets implement generator and checker algorithms for double byte packets.
Besides the choice of single byte or double byte packets for communication with the MAX14900E, another
selection criterion is the importance of code size versus execution speed. This application note provides
source code for three different assumptions. First, that small code size is paramount (and that execution
speed is secondary). Second, that execution speed is more important than code size. Third, that a balance
a desired between code size and execution speed. Curiously, this third “compromise” option proves as fast
as the second option in some microprocessor architectures, where table lookups are relatively expensive.
Page 1 of 11