Everything

使用例

CRC コードを生成し、送信データに追加する

解析した受信データから CRC コードを生成し、受信データが正しいかチェックする

 

[GUI設定例]

CRC演算器

CRC

使用する

CRC-8計算のための関数を生成

使用する

CRC-16計算のための関数を生成

使用しない

CRC-CCITT計算のための関数を生成

使用しない

初期値

0x0000

演算結果を反転する

使用しない

 

 

[API設定例]

tx_func.c

/* Start user code for adding. Do not edit comment generated here */

volatile uint8_t tx_buf[2];

volatile uint16_t result;

 

void tx_func(void)

{

       /* Set CRC module using CRC8 algorithm */

       R_CRC_SetCRC8(CRC_LSB);

 

       /* Restore transmit data */

       tx_buf[0] = 0xF0;

 

       /* Write data to CRC input register */

       R_CRC_Input_Data(tx_buf[0]);

 

       /* Get result from CRC output register */

       R_CRC_Get_Result((uint16_t *)&result);

 

       /* Restore CRC code */

       tx_buf[1] = (uint8_t)(result);

 

       /*** Transmit "tx_buf" ***/

}

/* End user code. Do not edit comment generated here */

 

 

 

 

rx_func.c

/* Start user code for adding. Do not edit comment generated here */

volatile uint8_t rx_buf[2];

volatile uint16_t result;

volatile uint8_t err_f;

 

void rx_func(void)

{

       /* Clare error flag */

       err_f = 0U;

 

       /*** Receive (Restore the receive data in "rx_buf") ***/

 

       /* Set CRC module using CRC8 algorithm */

       R_CRC_SetCRC8(CRC_LSB);

 

       /* Write data to CRC input register */

       R_CRC_Input_Data(rx_buf[0]);

 

       /* Get result from CRC output register */

       R_CRC_Get_Result((uint16_t *)&result);

 

       /* Check the receive data */

       if (rx_buf[1] != (uint8_t)(result))

       {

              /* Set error flag */

              err_f = 1U;

       }

}

/* End user code. Do not edit comment generated here */