ESB CRC calculation

Hi,

I have two nRF52840-DK with one transmitting and one receiving. I have been trying to calculate the CRC for an ESB packet. However, the CRC reported by the Rx board (using nrf_radio_rxcrc_get(NRF_RADIO)) differs with my calculations.

The ESB is configured using ESB_LEGACY_CONFIG with Dynamic Payload and 2-byte CRC. The code is based on the examples from the SDK /esb/esb_prx and /esb/esb_ptx

The packet is structured as follows (in order):

  • Address (0xE7E7E7, 3 bytes)
  • Prefix (0xE7, 1 byte)
  • Packet control field consisting of
    • Payload length (0x20, 6 bits)
    • PID (For simplicity, I only consider the case where PID=0x00, 2 bits)
    • NO_ACK (0x00, 1 bit)
  • Payload (32 bytes of 0x00)

For the above packet, the CRC reported by the receiving board is 0xFA78.

I calculated the CRC using an Excel implementation. It is not the most efficient but helps visualise and check the CRC calculation method. I have also validated the spreadsheet using this as guidance: https://srecord.sourceforge.net/crc16-ccitt.html. The calculated CRC for the above packet is 0xF2E2.

I've clearly done something wrong. Perhaps it is my understanding of the ESB packet structure/content or CRC calculation.

Any guidance would be appreciated.

Thanks

EsbRx.zipEsbTx.zipESB calculator.xlsx

  • Hello,

    It's a long time since I looked into this, and since it's done in hardware most of the time (at least for the radio) I must admit I don't remember the details. What I remember barely is that many (at least online) crc calculators need byte aligned data, while in this case it's not. So you may need to take a look at this old thread on how to calculate crc on bit (not byte):
    https://stackoverflow.com/questions/27332600/crc-bit-order-confusion 

    Kenneth

  • Hi Kenneth, 

    Thanks for the quick response.

    You are absolutely correct. I have not found any online calculators that perform a bitwise calculation of the CRC. Hence, I created one in Excel using manual long division (attached).

    I further validated my spreadsheet by deleting a bit from the Packet Control Field. The Address + (modified) Packet Control Field + Payload is then a multiple of 8-bits. This can be conveniently represented as bytes. Using the calculator at https://crccalc.com/ for CRC-16/AUG-CCITT, I get the same CRC as my spreadsheet.

    As the link suggests, the MSByte and MSBit ordering can be a source of error. I've simplified this by:

    1. Using the same value for all address and prefix bytes. Hence, byte-order is not an issue for the address/prefix.

    2. Using 0xE7 for the address/prefix. This is 0b11100111 so bit-order is not an issue for the address/prefix.

    3. Use payload of all 0x00. Hence, bit/byte order is not an issue for the payload.

    Is the ESB 2-byte CRC calculated as per CRC-CCITT? The documentation suggests so but doesn't say explicitly.

    Thanks

  • I can find several cases discussing calculation of CRC here on devzone, it should be the same for all variants of the nRF24-, nRF51, nRF52-series. I suggest to take a look at them, but afaik it should be standard CRC-16-CCITT (though I have seen someone mention False at the end, if that make any difference).

    Kenenth

Related