【英飞凌 - DAVE - CRC】

OVERVIEW:

This example uses the SW CRC APP to check the integrity of an incoming data frame.
The incoming frame is a 9-bytes frame (8bytes data + 1byte CRC checksum).

DESCRIPTION:

  • CRC_SW APP is used to calculate a CRC checksum based on a pre-determined polynomial. No
    algorithm control is selected for the CRC calculation.
  • UART APP is used to receive the incoming data frame. The incoming frame is a 9-bytes frame
    (8bytes data + 1byte CRC checksum). The 9th byte is the checksum byte.
  • SYSTIMER APP is used to generate a period SW timer of 0.5 seconds interval. It toggles the LED if checksum is matching, else LED is turned off.
  • DIGITAL_IO APP is used for LED toggling.
  • Main program polls for a 9bytes data frame. The incoming frame (8 bytes data) is used to
    calculate the CRC checksum. The result is used to compare against the checksum byte of the data frame. If result is matching, the LED toggles every 0.5 seconds, else LED is turned off.

REQUIRMENTS:

Boards Required: XMC4200 Platform2Go Board

HOW TO CREATE THE PROJECT:

  1. Open the DAVE CE and use “Add IDE New Project Wizard” on the toolbar to add a new
    DAVE Project.
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  2. Use the “Add New APP” in the toolbar to add APPs listed. Configure the App instances with
    the following configurations.
    在这里插入图片描述
    在这里插入图片描述
  • CRC_SW: Default settings taken.
    在这里插入图片描述
  • DIGITAL_IO_0:
    在这里插入图片描述
  • SYSTIMER_0: Default settings taken.
    在这里插入图片描述
  • UART_0: Default settings taken.
    在这里插入图片描述
  1. Use the “Manual Pin Allocator” found in the toolbar, configure the output pin for the LED and
    UART pins.
    在这里插入图片描述
  2. Generate the code for configurations made and change main.c accordingly.
    在这里插入图片描述
#include <DAVE.h>			//Declarations from DAVE Code Generation (includes SFR declarations)

uint8_t ReadData[9];
uint32_t CRCResult = 0;
uint32_t CRCResultmatch=0;

/**
 * @brief Periodic_Heartbeat()
 * SW timer triggered every 500ms. If CRC result matches, toggles LED. Else, LED is not turned on.
 */
void Periodic_Heartbeat(void)
{
	/*Toggles LED if CRC result matches with sent data frame*/
	if(CRCResultmatch)
	{
		DIGITAL_IO_ToggleOutput(&DIGITAL_IO_0);
	}
	else
	{
		DIGITAL_IO_SetOutputHigh(&DIGITAL_IO_0);
	}
}


/**
 * @brief main() - Application entry point
 * SW CRC is applied to an incoming frame to check the integrity of the received data. The incoming frame is a
 * 9-bytes frame (8bytes data + 1byte CRC checksum).
 */
int main(void)
{
  DAVE_STATUS_t status;
  uint32_t TimerId;

  status = DAVE_Init();		/* Initialization of DAVE Apps  */

  if(status == DAVE_STATUS_FAILURE)
  {
    /* Placeholder for error handler code. The while loop below can be replaced with an user error handler */
    XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
    while(1U)
    {
    }
  }

  /* Create Software Timer for LED evaluation and toggling*/
  TimerId = SYSTIMER_CreateTimer(500000U,SYSTIMER_MODE_PERIODIC,(void*)Periodic_Heartbeat,NULL);

  /* Start Software Timer */
  SYSTIMER_StartTimer(TimerId);


  /* Placeholder for user application code. The while loop below can be replaced with user application code. */
  while(1U)
  {
      /* Poll for data frame with 9 bytes of data. On data frame received, echo back the data to COM port
       * Data frame format: 8 bytes of data + 1 byte of CRC checksum
       */
	    UART_Receive(&UART_0, ReadData, 9);

	    while(UART_0.runtime->rx_busy)
        {
        }

        UART_Transmit(&UART_0, ReadData, 9);


	  /* Calculate the CRC based on the frame received. */
	  CRC_SW_CalculateCRC(&CRC_SW_0, ReadData, 8);

	  /* Read the CRC result */
      CRCResult = CRC_SW_GetCRCResult(&CRC_SW_0);

      /* Check if CRC result matches with dataframe result. If matches, CRCResultmatch=1 */
      if(CRCResult==ReadData[8])
      {
    	  CRCResultmatch=1;
      }
      else
      {
    	  CRCResultmatch=0;
      }
  }
}
  1. Build and download to the microcontroller.
  2. Using a terminal program (e.g. Docklight, MTTY) to send the data to the microcontroller.
    在这里插入图片描述

HOW TO TEST:

Download and run the demo in the uC.

OBSERVATIONS:

  • When a “Frame Correct Data” is sent, LED toggles at 0.5 seconds interval .
  • When a “Frame Wrong Data” is sent, LED turns off.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

六月悉茗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值