2018-08-05 09:08 AM
I try this to use this:
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
uint32_t CRCtest0 = 0;
uint32_t CRCtest1 = 0;
//uint32_t CRCtest2 = 0;
uint8_t txData[10]={0xF2, 0x10, 0x10, 0xE0, 0x3F, 0x35};
uint8_t crcdatatest1 [4] = {0xF2, 0x10, 0x10, 0xE0};
uint8_t crcdatatest2 [4] = {0xE0, 0x10, 0x10, 0xF2};
int main(void)
{
/* MCU Configuration----------------------------------------------------------*/
HAL_Init();
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_ADC1_Init();
MX_CAN1_Init();
MX_COMP1_Init();
MX_COMP2_Init();
MX_CRC_Init();
MX_UART4_Init();
MX_UART5_Init();
MX_SPI2_Init();
MX_I2C1_Init();
HAL_CRCEx_Polynomial_Set(&hcrc, 0x8005, CRC_POLYLENGTH_16B);
hcrc.Init.DefaultInitValueUse = 0;
hcrc.Init.InitValue = 0;
/* Infinite loop */
while (1)
{
CRCtest0 = HAL_CRC_Calculate(&hcrc, (uint32_t *)txData, 4);
CRCtest1 = HAL_CRC_Calculate(&hcrc, (uint32_t *)crcdatatest1, 4);
HAL_Delay(1000);
}
}
The returned values in CRCtest0 and CRCtest2 are both 0x8B0C which is not correct. According to CRC16/ARC polynomial the result should by 0x353F.
There is any other configuration that I’m missing?
Thanks,
Manel
2018-08-05 09:47 AM
>>There is any other configuration that I’m missing?
Don't know, you don't really show any configuration. The bit/byte ordering and shift direction will be critical.
2018-08-05 10:27 AM
Well I can understand where the 0x0C8B might come from. I can get to 0x353F with this
uint16_t Crc16Slow(uint16_t Crc, int Size, uint8_t *Buffer)
{
int i;
while(Size--)
{
Crc ^= *Buffer++; // Apply Data
for (i=0; i<8; i++) // 1-bit at a time
if (Crc & 0x0001)
Crc = (Crc >> 1) ^ 0xA001; // 0x8005 Polynomial used in ARC Reversed
else
Crc = (Crc >> 1);
}
return(Crc);
}
2018-08-05 01:36 PM
//****************************************************************************
/**
* @brief This function configures CRC Instance.
* @note This function is used to :
* -1- Enable peripheral clock for CRC.
* -2- Configure CRC functional parameters.
* @note Peripheral configuration is minimal configuration from reset values.
* Thus, some useless LL unitary functions calls below are provided as
* commented examples - setting is default configuration from reset.
* @param None
* @retval None
*/
void Configure_CRC(void)
{
/* (1) Enable peripheral clock for CRC *********************/
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_CRC);
/* (2) Configure CRC functional parameters ********************************/
/* Configure CRC calculation unit with user defined polynomial value, 16-bit long */
LL_CRC_SetPolynomialCoef(CRC, 0x8005);
LL_CRC_SetPolynomialSize(CRC, LL_CRC_POLYLENGTH_16B);
LL_CRC_SetInitialData(CRC, 0);
LL_CRC_SetInputDataReverseMode(CRC, LL_CRC_INDATA_REVERSE_BYTE);
LL_CRC_SetOutputDataReverseMode(CRC, LL_CRC_OUTDATA_REVERSE_BIT);
}
//****************************************************************************