Keywords: CRC, CRC-7, cyclic redundancy check, industrial output, PLC, programmable logic controller, C code, CRC generation, microprocessor, switch

Similar documents
variable 1. Start of Packet - is used to provide synchronization when parsing packets. Always 0xFC

variable 1. Start of Packet - is used to provide synchronization when parsing packets. Always 0xFC

CTT MODBUS-RTU COMMUNICATION PROTOCOL TEMPERATURE MONITOR DEVICE

MCW Application Notes 24 th February 2017

MTR-4. C8 Command to MODBUS Bridge User Manual F-1, No. 631, Chung Der Road, Sec 1, Taichung Taiwan.

GNetPlus Communication Protocol

TBS Unify Pro / SmartAudio

Signed/Unsigned Integer Arithmetic in C. Vineel Kovvuri

imetos LoRa Data payload structure

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

Ethernet to Digital I/O and Analog Input. (Model: IP-IO)

SIMCom_3G_CSD_Application Note_V1.00

1 SETTING UP GENERAL FUNCTION TYPE PROTOCOL MESSAGES COMMAND RETURN CODES... 6 TRANSACTION EXAMPLES...

Highlights. FP51 (FPGA based 1T 8051 core)

DULCOMETER Multi-parameter Controller dialog DACa

Technical Specification. Third Party Control Protocol. AV Revolution

Chapter 2: Secret Key

App Note Application Note: State-Driven Control of a dpasp using a Microchip PIC.

Input Channels: 4 differential or four single-ended. Address / Baud rate / range configurable by the user

DMTME Multimeters. Communication protocol. Technical specification V1.2 ABB

Modbus Protocol Guide for ZP2 Series Control Panels

//

AquaCER with TTL OUTPUT

RS232C Serial Interface for Pirani Diaphragm and Pirani Standard Gauges. Caution. binary 8 data bits 1 stop bit no parity bit no handshake

on a 35 mm top-hat rail (in accordance with DIN EN TH35) Ambient temperature Operation: C Storage: C

RS-232 Control of the Advantage DRI

Request for Comments: XXXX November Registration of a Georgian Character Set draft-giasher-geostd8-00.txt

Diagnostic Port Serial Interface for Capacitance Diaphragm Gauges

Computer Control of the Advantage DRC 4+4

APPENDIX- A REFERENCE IMPLEMENTATION OF BSF-128 ===============================================================

M2M/DMTME Instruments Communication protocol. Technical specification V.2.1 2CSG445011D0201

Verve IPAC Plug-in Wireless AC Module. Software Setup 3. DolphinView Software 3. Preparations 4 Transmit LINK Signals 4.

Heat meter PolluStat M-bus communication protocol description

The Roboteq Modbus Implementation User Manual

RS232C / RS485C Serial Interface for Cold Cathode and Cold Cathode Pirani Gauges

StarPRNT ios SDK User s Manual

RS232C / RS485C Serial Interface for Pirani Capacitance Diaphragm and Pirani Standard Gauges

SPARC INTERNATIONAL. Version1 SPARC Keyboard Specification

PCD1.W5200-A20. E-Line S-Serie RIO 8AO. Features. General technical data. Dimensions and installation

PCD1.A2000-A20. E-Line S-Serie RIO 6Rel 16A. Features. General technical data. Dimensions and installation

Motors I Automation I Energy I Transmission & Distribution I Coatings. Modbus RTU CFW701. User s Manual

CSEE bit AES decryption. Shrivathsa Bhargav Larry Chen Abhinandan Majumdar Shiva Ramudit. Spring 2008 Project Design Document

BENCHTOP INSTRUMENT. Digital AC/DC Power Meter. Operation Manual V1.0

Modbus Map: Conext XW/XW+ Device

// and verify that there is a sine wave with frequency <FREQUENCY> and

Modbus RTU CFW100. User s Manual. Phone: Fax: Web: -

Modbus communication protocol

Motors I Automation I Energy I Transmission & Distribution I Coatings. Modbus RTU CFW500. User s Manual

HDLC BCC 15.1 Data Link Protocol Description

Motors I Automation I Energy I Transmission & Distribution I Coatings. Modbus RTU CFW300. User s Manual

UNPACKING THE PACKED UNPACKER: REVERSING AN ANDROID ANTI-ANALYSIS NATIVE LIBRARY Maddie Stone Google, USA

PLC Lite Host Message Protocol Specification

JDICON 400/500 JDICON 401/501. B Interface Description. Universal process controller

MODBUS Communication Protocol

#include <stdio.h> // // Global CONSTANTS

IEC /104 Communications Protocol

Using the USB and Serial Interfaces

ADV7610 SOFTWARE MANUAL SOFTWARE MANUAL. Documentation of the Register Maps. Rev. 0

Specifiche generali protocollo MODBUS-RTU Rev. 10 (inglese) REVISIONS

DATA SHEET. article numbers P125-1b & P125-1g

GSA GAT PROTOCOL V Game Authentication Terminal

Flexi Soft T E L E G R A M M L I S T I N G

Modbus Map: MPPT60 Device

SXH Protocol by Spinel Version 3.0 Date:

Description. thanos ModBus. thanos SR ModBus

ID: Sample Name: Q3dY56x3hp Cookbook: defaultlinuxfilecookbook.jbs Time: 04:08:56 Date: 21/08/2018 Version:

PCD1.E1000-A10. E-Line S-Serie RIO 12DI. Features. General technical data. Dimensions and installation

ADV7612 SOFTWARE MANUAL SOFTWARE MANUAL. Documentation of the Register Maps. Rev. A

Intro (with some history) Issues ow, ow, ow, ow, ow, ow, ow, ow, Disclosure/Timeline CHIASMUS cipher

MICROPROCESSOR CONTROLLER RE15

Security Analysis of Lightweight Authentication Protocol from WISTP ,2) P, Xiao FuP P, Chen Dan-weiP P, Wang Ru-chuanP

CS 4400 Fall 2018 Midterm Exam 2 Practice (Version 2)

ANM071. Keypad decoding technique using TSC80251G1. 1. Description 2. TSC80251G Keyboard interrupt Power down mode

TCG Algorithm Registry

Modbus Map: Conext MPPT Device

S1C17 Series Small Memory Programming

1 Introduction Revision History... 4

University of Texas at El Paso Electrical and Computer Engineering Department

Software Manual. Applicable Models TSP100ECO TSP100GT TSP100LAN TSP100U/PUSB. Rev. 5.5

Interface Control Document

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018

Technical Information. Command overview of Vision Systems

AN198 I NTEGRATING SDCC 8051 TOOLS INTO THE SILICON LABS IDE. 4. Configure the Tool Chain Integration Dialog. 1. Introduction. 2.

MODEL TDAI-2170 INTEGRATED AMPLIFIER EXTERNAL CONTROL MANUAL

Garmin Image (IMG) File Format. Herbert Oppmann

RTX64. Supported Network Interface Cards IntervalZero, Inc. IZ-DOC-X R32 March 2017

RTX64. Supported Network Interface Cards

SIRKOM'Digital'Signage'Div.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''MedeaWiz 'Sprite' High'Definition'Video'Player' User'Manual'

Aptio 5.x Status Codes

Protocol Description. thanos ModBus. thanos SR ModBus

Mahesh V. Tripunitara and Samuel S. Wagsta, Jr. COAST Laboratory. Purdue University. COAST TR-98/01.

Best of Oracle Security by Red-Database-Security

KINGSTAR 3.6. SUPPORTED NETWORK INTERFACE CARDS KS-DOC-x R20

1CAPI INFORMATION VALUES. August Software Reference CAPI Information Values 1

RTX64. Supported Network Interface Cards

JPEG File Layout and Format

Survey. Motivation 29.5 / 40 class is required

INNOVATIVE TECHNOLOGY LTD

8x8 HDMI over CAT5 Matrix with IR Pass-through

Revision History. Rev Date Author Description A 27 Aug 99 Emil Farkas Initial release. Approvals: Author. VP. Engineering

Transcription:

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

API Conventions Used Each code set defines two function calls, one for the CRC generator, and another for the CRC checker. Please note that in these code examples, unsigned char is an alias for an 8-bit unsigned value, sometimes labeled differently, perhaps something like UINT8. Function return values are either unsigned char or bool, but some microprocessors execute code faster if the return values are int instead, the native storage size of that microprocessor. The single byte generator function call looks something like: send2 = generator (send1); Send1 is the byte to send to the MAX14900E. The code should transmit send1 followed by send2 to the MAX14900E. Likewise, the double byte generator function call looks something like this: send3 = generator (send1, send2); The user should send 3 bytes, send1, followed by send2, then send3, over the SPI interface. While the microprocessor sends configuration settings to the MAX14900E over the SPI interface, the MAX14900E simultaneously returns status information back to the microprocessor. The single byte checker looks something like: flag = checker (ret1, ret2); The Boolean flag is true (!= 0) if the return byte and CRC match. The double byte checker looks like: flag = checker (ret1, ret2, ret3); Small Code Size The code examples in this section use loops to build the CRC one bit at a time. For this reason, they are not so fast, but compile compactly. These code snippets rely on a helper routine, Loop_CRC, to perform the actual bit-at-a-time CRC calculation. unsigned char Loop_CRC (unsigned char crc, unsigned char byte) int i; for (i = 0; i < 8; i++) crc <<= 1; if (crc & 0x80) Page 2 of 11

crc ^= 0xB7; 0x37 with MSBit on purpose if (byte & 0x80) crc ^=1; byte <<= 1; return crc; unsigned char crcsmallencode8 (unsigned char byte1) synd = Loop_CRC (0x7f, byte1); return Loop_CRC (synd, 0x80) 0x80; bool crcsmallcheck8 (unsigned char byte1, unsigned char byte2) synd = Loop_CRC (0x7f, byte1); return Loop_CRC (synd, byte2) == 0; unsigned char Loop_CRC (unsigned char crc, unsigned char byte) int i; for (i = 0; i < 8; i++) crc <<= 1; if (crc & 0x80) crc ^= 0xB7; 0x37 with MSBit on purpose if (byte & 0x80) crc ^=1; byte <<= 1; Page 3 of 11

return crc; unsigned char crcsmallencode16 (unsigned char byte1, unsigned char byte2) synd = Loop_CRC (0x7f, byte1); synd = Loop_CRC (synd, byte2); return Loop_CRC (synd, 0x80) 0x80; bool crcsmallcheck16 (unsigned char byte1, unsigned char byte2, unsigned char byte3) synd = Loop_CRC (0x7f, byte1); synd = Loop_CRC (synd, byte2); return Loop_CRC (synd, byte3) == 0; Fast Execution The code examples in this section trade code size for speed. Two 128-byte tables encode one full byte of data per table access. Note that if the user only wishes to protect data sent to the MAX14900E, and uses single byte transactions, then the user only needs the second table. const unsigned char propagate8_next0 [128] = 0x00, 0x6E, 0x6B, 0x05, 0x61, 0x0F, 0x0A, 0x64, 0x75, 0x1B, 0x1E, 0x70, 0x14, 0x7A, 0x7F, 0x11, 0x5D, 0x33, 0x36, 0x58, 0x3C, 0x52, 0x57, 0x39, 0x28, 0x46, 0x43, 0x2D, 0x49, 0x27, 0x22, 0x4C, 0x0D, 0x63, 0x66, 0x08, 0x6C, 0x02, 0x07, 0x69, 0x78, 0x16, 0x13, 0x7D, 0x19, 0x77, 0x72, 0x1C, 0x50, 0x3E, 0x3B, 0x55, 0x31, 0x5F, 0x5A, 0x34, 0x25, 0x4B, 0x4E, 0x20, 0x44, 0x2A, 0x2F, 0x41, 0x1A, 0x74, 0x71, 0x1F, 0x7B, 0x15, 0x10, 0x7E, 0x6F, 0x01, 0x04, 0x6A, 0x0E, 0x60, 0x65, 0x0B, Page 4 of 11

0x47, 0x29, 0x2C, 0x42, 0x26, 0x48, 0x4D, 0x23, 0x32, 0x5C, 0x59, 0x37, 0x53, 0x3D, 0x38, 0x56, 0x17, 0x79, 0x7C, 0x12, 0x76, 0x18, 0x1D, 0x73, 0x62, 0x0C, 0x09, 0x67, 0x03, 0x6D, 0x68, 0x06, 0x4A, 0x24, 0x21, 0x4F, 0x2B, 0x45, 0x40, 0x2E, 0x3F, 0x51, 0x54, 0x3A, 0x5E, 0x30, 0x35, 0x5B ; const unsigned char propagate8_next1 [128] = 0xB7, 0xD9, 0xDC, 0xB2, 0xD6, 0xB8, 0xBD, 0xD3, 0xC2, 0xAC, 0xA9, 0xC7, 0xA3, 0xCD, 0xC8, 0xA6, 0xEA, 0x84, 0x81, 0xEF, 0x8B, 0xE5, 0xE0, 0x8E, 0x9F, 0xF1, 0xF4, 0x9A, 0xFE, 0x90, 0x95, 0xFB, 0xBA, 0xD4, 0xD1, 0xBF, 0xDB, 0xB5, 0xB0, 0xDE, 0xCF, 0xA1, 0xA4, 0xCA, 0xAE, 0xC0, 0xC5, 0xAB, 0xE7, 0x89, 0x8C, 0xE2, 0x86, 0xE8, 0xED, 0x83, 0x92, 0xFC, 0xF9, 0x97, 0xF3, 0x9D, 0x98, 0xF6, 0xAD, 0xC3, 0xC6, 0xA8, 0xCC, 0xA2, 0xA7, 0xC9, 0xD8, 0xB6, 0xB3, 0xDD, 0xB9, 0xD7, 0xD2, 0xBC, 0xF0, 0x9E, 0x9B, 0xF5, 0x91, 0xFF, 0xFA, 0x94, 0x85, 0xEB, 0xEE, 0x80, 0xE4, 0x8A, 0x8F, 0xE1, 0xA0, 0xCE, 0xCB, 0xA5, 0xC1, 0xAF, 0xAA, 0xC4, 0xD5, 0xBB, 0xBE, 0xD0, 0xB4, 0xDA, 0xDF, 0xB1, 0xFD, 0x93, 0x96, 0xF8, 0x9C, 0xF2, 0xF7, 0x99, 0x88, 0xE6, 0xE3, 0x8D, 0xE9, 0x87, 0x82, 0xEC ; unsigned char crcfastencode8 (unsigned char byte1) synd = (byte1 & 0x80)? 0xEC : 0x5B; 6C & 5B before optimization synd ^= byte1; return propagate8_next1[synd]; bool crcfastcheck8 (unsigned char byte1, unsigned char byte2) unsigned char const *ptr; Page 5 of 11

synd = (byte1 & 0x80)? 0xEC : 0x5B; synd ^= byte1; ptr = byte2 & 0x80? propagate8_next1 : propagate8_next0; return (ptr[synd] ^ byte2) == 0; const unsigned char propagate8_next0 [128] = 0x00, 0x6E, 0x6B, 0x05, 0x61, 0x0F, 0x0A, 0x64, 0x75, 0x1B, 0x1E, 0x70, 0x14, 0x7A, 0x7F, 0x11, 0x5D, 0x33, 0x36, 0x58, 0x3C, 0x52, 0x57, 0x39, 0x28, 0x46, 0x43, 0x2D, 0x49, 0x27, 0x22, 0x4C, 0x0D, 0x63, 0x66, 0x08, 0x6C, 0x02, 0x07, 0x69, 0x78, 0x16, 0x13, 0x7D, 0x19, 0x77, 0x72, 0x1C, 0x50, 0x3E, 0x3B, 0x55, 0x31, 0x5F, 0x5A, 0x34, 0x25, 0x4B, 0x4E, 0x20, 0x44, 0x2A, 0x2F, 0x41, 0x1A, 0x74, 0x71, 0x1F, 0x7B, 0x15, 0x10, 0x7E, 0x6F, 0x01, 0x04, 0x6A, 0x0E, 0x60, 0x65, 0x0B, 0x47, 0x29, 0x2C, 0x42, 0x26, 0x48, 0x4D, 0x23, 0x32, 0x5C, 0x59, 0x37, 0x53, 0x3D, 0x38, 0x56, 0x17, 0x79, 0x7C, 0x12, 0x76, 0x18, 0x1D, 0x73, 0x62, 0x0C, 0x09, 0x67, 0x03, 0x6D, 0x68, 0x06, 0x4A, 0x24, 0x21, 0x4F, 0x2B, 0x45, 0x40, 0x2E, 0x3F, 0x51, 0x54, 0x3A, 0x5E, 0x30, 0x35, 0x5B ; const unsigned char propagate8_next1 [128] = 0xB7, 0xD9, 0xDC, 0xB2, 0xD6, 0xB8, 0xBD, 0xD3, 0xC2, 0xAC, 0xA9, 0xC7, 0xA3, 0xCD, 0xC8, 0xA6, 0xEA, 0x84, 0x81, 0xEF, 0x8B, 0xE5, 0xE0, 0x8E, 0x9F, 0xF1, 0xF4, 0x9A, 0xFE, 0x90, 0x95, 0xFB, 0xBA, 0xD4, 0xD1, 0xBF, 0xDB, 0xB5, 0xB0, 0xDE, 0xCF, 0xA1, 0xA4, 0xCA, 0xAE, 0xC0, 0xC5, 0xAB, 0xE7, 0x89, 0x8C, 0xE2, 0x86, 0xE8, 0xED, 0x83, 0x92, 0xFC, 0xF9, 0x97, 0xF3, 0x9D, 0x98, 0xF6, 0xAD, 0xC3, 0xC6, 0xA8, 0xCC, 0xA2, 0xA7, 0xC9, 0xD8, 0xB6, 0xB3, 0xDD, 0xB9, 0xD7, 0xD2, 0xBC, 0xF0, 0x9E, 0x9B, 0xF5, 0x91, 0xFF, 0xFA, 0x94, 0x85, 0xEB, 0xEE, 0x80, 0xE4, 0x8A, 0x8F, 0xE1, 0xA0, 0xCE, 0xCB, 0xA5, 0xC1, 0xAF, 0xAA, 0xC4, 0xD5, 0xBB, 0xBE, 0xD0, 0xB4, 0xDA, 0xDF, 0xB1, 0xFD, 0x93, 0x96, 0xF8, 0x9C, 0xF2, 0xF7, 0x99, Page 6 of 11

0x88, 0xE6, 0xE3, 0x8D, 0xE9, 0x87, 0x82, 0xEC ; This is the fast (one byte at a time) algorithm This is so fast that one could benefit from running it in-line unsigned char crcfastencode16 (unsigned char byte1, unsigned char byte2) unsigned char const *ptr; synd = (byte1 & 0x80)? 0xEC : 0x5B; synd ^= byte1; ptr = byte2 & 0x80? propagate8_next1 : propagate8_next0; synd = ptr[synd] ^ byte2; return propagate8_next1[synd]; bool crcfastcheck16 (unsigned char byte1, unsigned char byte2, unsigned char byte3) unsigned char const *ptr; synd = (byte1 & 0x80)? 0xEC : 0x5B; synd ^= byte1; ptr = byte2 & 0x80? propagate8_next1 : propagate8_next0; synd = ptr[synd] ^ byte2; ptr = byte3 & 0x80? propagate8_next1 : propagate8_next0; return (ptr[synd] ^ byte3) == 0; Balanced The code examples in this section strike a balance between code size and execution speed. One table lookup encodes 7 bits of data into the CRC. The eighth bit is encoded using techniques used in the sizeoptimized code. Some Harvard architecture devices have relatively expensive table lookup execution times, and for this class of microprocessor, this balanced code might execute as quickly as the speed optimized code, or perhaps even faster. Page 7 of 11

unsigned char propagate7 [128] = 0x00, 0x6E, 0xDC, 0xB2, 0xD6, 0xB8, 0x0A, 0x64, 0xC2, 0xAC, 0x1E, 0x70, 0x14, 0x7A, 0xC8, 0xA6, 0xEA, 0x84, 0x36, 0x58, 0x3C, 0x52, 0xE0, 0x8E, 0x28, 0x46, 0xF4, 0x9A, 0xFE, 0x90, 0x22, 0x4C, 0xBA, 0xD4, 0x66, 0x08, 0x6C, 0x02, 0xB0, 0xDE, 0x78, 0x16, 0xA4, 0xCA, 0xAE, 0xC0, 0x72, 0x1C, 0x50, 0x3E, 0x8C, 0xE2, 0x86, 0xE8, 0x5A, 0x34, 0x92, 0xFC, 0x4E, 0x20, 0x44, 0x2A, 0x98, 0xF6, 0x1A, 0x74, 0xC6, 0xA8, 0xCC, 0xA2, 0x10, 0x7E, 0xD8, 0xB6, 0x04, 0x6A, 0x0E, 0x60, 0xD2, 0xBC, 0xF0, 0x9E, 0x2C, 0x42, 0x26, 0x48, 0xFA, 0x94, 0x32, 0x5C, 0xEE, 0x80, 0xE4, 0x8A, 0x38, 0x56, 0xA0, 0xCE, 0x7C, 0x12, 0x76, 0x18, 0xAA, 0xC4, 0x62, 0x0C, 0xBE, 0xD0, 0xB4, 0xDA, 0x68, 0x06, 0x4A, 0x24, 0x96, 0xF8, 0x9C, 0xF2, 0x40, 0x2E, 0x88, 0xE6, 0x54, 0x3A, 0x5E, 0x30, 0x82, 0xEC ; unsigned char crcmediumencode8 (unsigned char byte1) synd = (byte1 ^ 0xEC); synd = propagate7[synd] ^ 0x80; return synd 0x80; bool crcmediumcheck8 (unsigned char byte1, unsigned char byte2) synd = (byte1 ^ 0xEC); Page 8 of 11

synd = propagate7[synd] ^ byte2; return synd == 0; unsigned char propagate7 [128] = 0x00, 0x6E, 0xDC, 0xB2, 0xD6, 0xB8, 0x0A, 0x64, 0xC2, 0xAC, 0x1E, 0x70, 0x14, 0x7A, 0xC8, 0xA6, 0xEA, 0x84, 0x36, 0x58, 0x3C, 0x52, 0xE0, 0x8E, 0x28, 0x46, 0xF4, 0x9A, 0xFE, 0x90, 0x22, 0x4C, 0xBA, 0xD4, 0x66, 0x08, 0x6C, 0x02, 0xB0, 0xDE, 0x78, 0x16, 0xA4, 0xCA, 0xAE, 0xC0, 0x72, 0x1C, 0x50, 0x3E, 0x8C, 0xE2, 0x86, 0xE8, 0x5A, 0x34, 0x92, 0xFC, 0x4E, 0x20, 0x44, 0x2A, 0x98, 0xF6, 0x1A, 0x74, 0xC6, 0xA8, 0xCC, 0xA2, 0x10, 0x7E, 0xD8, 0xB6, 0x04, 0x6A, 0x0E, 0x60, 0xD2, 0xBC, 0xF0, 0x9E, 0x2C, 0x42, 0x26, 0x48, 0xFA, 0x94, 0x32, 0x5C, 0xEE, 0x80, 0xE4, 0x8A, 0x38, 0x56, 0xA0, 0xCE, 0x7C, 0x12, 0x76, 0x18, 0xAA, 0xC4, 0x62, 0x0C, 0xBE, 0xD0, 0xB4, 0xDA, 0x68, 0x06, 0x4A, 0x24, 0x96, 0xF8, 0x9C, 0xF2, 0x40, 0x2E, 0x88, 0xE6, 0x54, 0x3A, 0x5E, 0x30, 0x82, 0xEC ; unsigned char crcmediumencode16 (unsigned char byte1, unsigned char byte2) synd = (byte1 ^ 0xEC); synd = propagate7[synd] ^ byte2; synd = propagate7[synd] ^ 0x80; return synd 0x80; Page 9 of 11

bool crcmediumcheck16 (unsigned char byte1, unsigned char byte2, unsigned cha r byte3) synd = (byte1 ^ 0xEC); synd = propagate7[synd] ^ byte2; synd = propagate7[synd] ^ byte3; return synd == 0; Comparisons To get some idea how efficient these CRC calculations are, this code was implemented on a Microchip PIC24F family running at 16 MIPS (32MHz internal CPU clock). This is a 16-bit data path microprocessor with 24-bit instructions. The only modifications to the code were to change the return values to short, which the C compiler interprets as a signed 16-bit value, its native data width. Code size is determined from compiler and linker tables. An ancillary program generates 1,024 random 8-, 16-, or 24-bit values. Times reported are an average of these 1,024 tests. Table 1 summarizes the data obtained using the Microchip C compiler and their code emulator. For code using table lookups, the size is specified in bytes as CONST. Table 1. Execution Time and Code Size Comparison Using a PIC24 Algorithm Bytes (PGM + CONST) Encode Time (µs) Decode Time (µs) Compact Single Byte 219 24.8 25.5 Speedy Single Byte 570 (186 + 384) 1.72 3.00 Balanced Single Byte 323 (195 + 128) 2.06 2.44 Compact Double Byte 267 37.2 37.8 Speedy Double Byte 723 (339 + 384) 3.19 4.34 Balanced Double Byte 473 (345 + 128) 3.02 3.40 Page 10 of 11

Different microprocessors will yield different results, but in the case of the PIC24F, the speedy algorithms need not be used. If interested in a fast CRC conversion, both the speedy and the balanced algorithms should be benchmarked on the target processor to determine which is better. Conclusion This application note has shown how to code CRC algorithms on a microprocessor communicating with a MAX14900E octal high-speed industrial switch. Taking advantage of the C code examples in this application note is a worry-free way to implement this extra protection. In some cases, some benchmarking should be performed on the target processor, especially if fast execution speed is a priority. Related Parts MAX14900E Octal, High-Speed, Industrial, High-Side Switch Free Samples More Information For Technical Support: http:www.maximintegrated.com/en/support For Samples: http:www.maximintegrated.com/en/samples Other Questions and Comments: http:www.maximintegrated.com/en/contact Application Note 6002: http:www.maximintegrated.com/en/an6002 APPLICATION NOTE 6002, AN6002, AN 6002, APP6002, Appnote6002, Appnote 6002 2014 Maxim Integrated Products, Inc. The content on this webpage is protected by copyright laws of the United States and of foreign countries. For requests to copy this content, contact us. Additional Legal Notices: http:www.maximintegrated.com/en/legal Page 11 of 11