主题中讨论的其他器件: MSP432E401Y
尊敬的 TI 专家:
我正在 MSP432E401Y 和 MSP430FR5739之间建立通信协议、这需要生成16位硬件 CRC。 我正在使用 MSP432和 MSP430上的驱动程序库与每个 CRC 驱动程序进行连接、以生成16位 CRC。 驱动器的数据输入一次为1字节(unsigned char 或 uint8_t 类型)。
MSP432有多种 CRC 标准可供选择、但最接近 MSP430的是 CCITT 选项。 MSP430具有16位 CRC-CCITT-BR (BR=字节反转?) 标准(无法更改)、因此与 MSP432不完全相同。
下面是我正在关注的 MSP432E401Y 示例、经过修改后显示了我的 CRC 配置和输入的参数。 我为其创建校验和的数据也是相同的。 CRC16 结果 =无符号短整型11111101110100b (二进制)
/* * ======== crc.c ======== */ #include <stdint.h> #include <stddef.h> #include <stdlib.h> /* Driver Header files */ #include <ti/drivers/CRC.h> /* Driver configuration */ #include "ti_drivers_config.h" /* Expected CRC for CRC_32_IEEE with full endianness reversal */ static const uint32_t expectedCrc = 0x4C4B4461; /* Example test vector */ static const size_t srcSize = 3; static const uint8_t src [] = { 0x02,0x08,0x01 }; /* ======== mainThread ======== */ void *mainThread(void *arg0) { int_fast16_t status; uint16_t result; CRC_Handle handle; CRC_Params params; /* Initialize the drivers */ CRC_init(); /* Set data processing options, including endianness control */ CRC_Params_init(¶ms); params.byteSwapInput = CRC_BYTESWAP_UNCHANGED; params.returnBehavior = CRC_RETURN_BEHAVIOR_BLOCKING; params.polynomial = CRC_POLYNOMIAL_CRC_16_CCITT; params.dataSize = CRC_DATA_SIZE_8BIT; params.seed = 0xFFFF; /* Open the driver using the settings above */ handle = CRC_open(CONFIG_CRC_0, ¶ms); if (handle == NULL) { /* If the handle is already open, execution will stop here */ while(1); } /* Calculate the CRC of all 32 bytes in the source array */ status = CRC_calculateFull(handle, src, srcSize, &result); if (status != CRC_STATUS_SUCCESS) { /* If the CRC engine is busy or if an error occurs execution will stop here */ while(1); } /* Close the driver to allow other users to access this driver instance */ CRC_close(handle); return NULL; }
下面是我正在关注的 MSP430FR5739的示例代码、经过修改后显示了我的配置、参数和输入的数据。 生成的 CRC16 crcResult = unsigned int 1011011111011001b (二进制)
#include "driverlib.h" uint16_t crcResult; void main (void) { uint16_t crcSeed = 0xFFFF; uint8_t data[] = {0x02, 0x08, 0x01}; uint8_t i; //Stop WDT WDT_A_hold(WDT_A_BASE); //Set P1.0 as an output GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0); //Set the CRC seed CRC_setSeed(CRC_BASE, crcSeed); for (i = 0; i < 5; i++) { //Add all of the values into the CRC signature CRC_set8BitDataReversed(CRC_BASE, data[i]); } //Save the current CRC signature checksum to be compared for later crcResult = CRC_getResult(CRC_BASE); //Enter LPM4, interrupts enabled __bis_SR_register(LPM4_bits); __no_operation(); }
我已经尝试在 MSP430上输入反转字节、希望在没有反转字节的情况下返回 CCITT 标准、因此我可以将其与 MSP432上的 CCITT CRC16标准匹配。 但是、我可能会实施这种错误。 可以有人告诉我如何修改 MSP430或 MSP432上的此示例代码、以便与两个器件上计算出的 CRC 相匹配。
希望这可以通过使用这两个器件上的硬件 CRC 生成器来实现。 希望找到解决方案。