AnsweredAssumed Answered

Use stm32 crc to compare DS18B20 crc

Question asked by Flour Beur on Feb 25, 2018
Latest reply on Feb 25, 2018 by Clive One

Hello friend,


I have DS18B20. And I read his uniq ID with CRC.


And I know, that STM has crc calculator. 


So I read data from DS18B20:

  • 0xab 0x1 0x4b 0x46 0x7f 0xff 0x5 0x10 : CRC 0x92


And I use internal calculator on this datas.

But result is wrong, because I get: 0x19


And you can see 0x92 is different from 0x19.


For example:

read ID with CRC.

uint8_t *p = ds18b20_read_serial_number();


And CRC calculation:

uint8_t test_crc = CRC_Calculate8(p, 8, 1);


Any idea, what is wrong?


Here is function to calc CRC in STM32F767zi.

uint32_t CRC_Calculate8(uint8_t* arr, uint32_t count, uint8_t reset)
/* Reset CRC data register if necessary */
if (reset) {
/* Reset generator */
LL_CRC_ResetCRCCalculationUnit(CRC); //CRC->CR = CRC_CR_RESET;

/* Calculate CRC */
while (count--) {
/* Set new value */
LL_CRC_FeedData8(CRC, *arr++); //CRC->DR = *arr++;

/* Return data */
return LL_CRC_ReadData8(CRC); //CRC->DR;