User`s manual

RX62N Group, RX621 Group 5. Usage Examples
5.13. CRC calculator
Figure 5-24 shows an example of CRC usage.
The payload and CRC checksum have been received from a remote unit.
The CRC calculator is used to check that the payload is correct.
/* Peripheral driver function prototypes */
#include "r_pdl_crc.h"
/* RPDL device-specific definitions */
#include "r_pdl_definitions.h"
void main(void)
{
uint16_t crc_result;
/* Configure the CRC to use the CCITT polynomial; LSB first */
R_CRC_Create(
PDL_CRC_POLY_CRC_CCITT | PDL_CRC_LSB_FIRST
);
/* Write the payload data */
R_CRC_Write(
0xF0
);
/* Write the first half of the CRC checksum */
R_CRC_Write(
0x8F
);
/* Write the second half of the CRC checksum */
R_CRC_Write(
0xF7
);
/* Read the CRC calculation result */
R_CRC_Read(
PDL_NO_DATA,
&crc_esult
);
/* Shutdown the CRC unit */
R_CRC_Destroy(
);
}
Figure 5-24: Example of CRC calculation
R20UT0084EE0112 Rev.1.12 Page 5-45
July. 16, 2014