<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>CRC calculation on nRF52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/111672/crc-calculation-on-nrf52840</link><description>Hi, 
 I am using nrf52840 and SDK17.1.0. 
 I need to calculate CRC16 for communication with an another module. I found that we have an API for that. I would like to know what CRC calculation method the function sys_crc_t sys_crc_calc (const uint8_t *</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 31 May 2024 07:46:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/111672/crc-calculation-on-nrf52840" /><item><title>RE: CRC calculation on nRF52840</title><link>https://devzone.nordicsemi.com/thread/486803?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 07:46:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b0664bf-6302-4bb4-a672-aa68a521b451</guid><dc:creator>Den</dc:creator><description>&lt;p&gt;Hello Tesc,&lt;/p&gt;
&lt;p&gt;Thanks very much for your clarifying answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;D&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CRC calculation on nRF52840</title><link>https://devzone.nordicsemi.com/thread/486718?ContentTypeID=1</link><pubDate>Thu, 30 May 2024 15:26:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54deff6c-aa09-488e-baff-d3600347407b</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Both of the functions you mention does CRC calculations from a given array of data.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.1.0%2Fgroup__crc16.html&amp;amp;anchor=ga6fc3ea48473dbf4ef615fef035b0ff83"&gt;crc16_compute()&lt;/a&gt; uses CRC-16-CCITT (polynomial 0x1021, that is x^16 + x^12 + x^5 + 1) with initial value of 0xFFFF (default) or the value you provide (via value pointed to by non-null p_crc).&lt;/p&gt;
&lt;p&gt;The above CRC calculation is also described in the Bluetooth Core Specification, then described as the &amp;quot;CCITT generator polynomial g(D) = D^16 + D^12 + D^5 + 1 (i.e. 210041 in octal representation)&amp;quot;.&lt;/p&gt;
&lt;p&gt;The function is found in the HCI transport library of the SDK, which indicates it is used by Bluetooth Host Controller Interface (HCI).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.1.0%2Fgroup__sys__crc.html&amp;amp;anchor=gad4fefc76299b6b2d69a5b360f7f8aaea"&gt;sys_crc_calc()&lt;/a&gt; uses CRC-16-ANSI (polynomial 0x8005, that is x^16 + x^15 + x^2 + 1,) with 0x0000 initial value.&lt;/p&gt;
&lt;p&gt;The function is found as part of the 802.15.4 stack API, which is a precompiled library distributed as part of the nRF5 SDK. It has been used for samples and testing, but is currently not used from anywhere within the nRF5 SDK. (I was not able to find any internal uses within the 802.15.4 library either.)&lt;/p&gt;
&lt;p&gt;To answer your questions:&lt;/p&gt;
[quote user=""]Does it use the same one as&amp;nbsp;&lt;span&gt;&lt;strong&gt;CRC16 compute&lt;/strong&gt;&lt;/span&gt;[/quote]
&lt;p&gt;No, the polynomials differ.&lt;/p&gt;
[quote user=""]If not what does it use and does it have any advantages in terms of memory usage, speed, configuration or anything else?[/quote]
&lt;p&gt;I am afraid we do not have any clear answer to this, apart from what polynomials and initial values are used, but with that knowledge I am sure there is extensive litterature to be found describing drawbacks and advantages for each of them.&lt;/p&gt;
&lt;p&gt;As for the implementations used in the SDK, one uses more operations but consistent branching while the other uses fewer operations but includes an if/else statement. It is hard to tell which one has the better performance (if there is a noticeable difference at all), but I suggest you to do some testing if this is important to you.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>