14.7 Configuring the CRC
The following steps illustrate how to properly configure the CRC.
- Determine if the automatic program memory scan will be used with the scanner or manual calculation through the SFR interface and perform the actions specified in 14.4 CRC Data Sources, depending on which decision was made.
- If desired, seed a starting CRC value into the CRCACC14.12.4 CRCACC registers.
- Program the CRCXOR14.12.6 CRCXOR registers with the desired generator polynomial.
- Program the DLENbits with the length of the data word - 1 (refer to Figure 14-1). This determines how many times the shifter will shift into the accumulator for each data word.
- Program the PLEN bits with the length of the polynomial -2 (refer to Figure 14-1).
- Determine whether shifting in trailing zeros is desired and set the ACCM bit accordingly.
- Likewise, determine whether the MSb or LSb should be shifted first and write the SHIFTM bit accordingly.
- Set the GO bit to begin the shifting process.
- If manual SFR entry is used, monitor the FULL bit. When FULL = 0, another word of data can be written to the CRCDAT14.12.3 CRCDAT registers, keeping in mind that Most Significant Byte, CRCDATH, should be written first if the data has more than eight bits, as the shifter will begin upon the CRCDATL register being written.
- If the scanner is used, the scanner will automatically stuff words into the CRCDAT registers as needed, as long as the SCANGO bit is set.
- If using the Flash memory scanner, monitor the PIRx SCANIF bit (or the SCANGO bit) for the scanner to finish pushing information into the CRCDATA registers. After the scanner is completed, monitor the BUSY bit to determine that the CRC has been completed and the check value can be read from the CRCACC registers. If both the interrupt flags are set (or both BUSY and SCANGO bits are cleared), the completed CRC calculation can be read from the CRCACC registers.
- If manual entry is used, monitor the BUSY bit to determine when the CRCACC registers hold the valid check value.