Skip to main content
Visitor II
April 23, 2024
Solved

How to swap the SPI CRC value and then transmit it?

  • April 23, 2024
  • 2 replies
  • 1935 views

I enabled the SPI CRC calculation (with a length SPI_CRC_LENGTH_16BIT) in my STM32H563ZI  master application. During Tx, I want the 2 bytes of the calculated CRC to be swapped and transmitted i.e. a CRC of 0xABCD must be sent out as 0xCD 0xAB and not as 0xAB 0xCD.

Can someone let me know how to do this? 

Thanks.

 

    This topic has been closed for replies.
    Best answer by AScha.3

    Well, i never used it, so i am just guessing:

    - if you use the spi-auto-generated crc, you cannot "swap" this. It expects an STM32 with same crc unit as target.

    - if you calculate the crc yourself , maybe with the crc unit or just in software, swap bytes, and put it as last value to the send-array , then send all; this should work, if you calculate crc exact in the way, the target expects.

    2 replies

    Super User
    April 23, 2024

    >CRC of 0xABCD must be sent out as 0xCD 0xAB and not as 0xAB 0xCD.

    Why this ? 

    WCareyAuthor
    Visitor II
    April 23, 2024

    My slave application running on a different target receives the CRC in that order ( lower byte first ).

    WCareyAuthor
    Visitor II
    April 23, 2024

    Can this be done using CRC peripheral itself rather than using SPI's CRC feature?

    AScha.3Answer
    Super User
    April 23, 2024

    Well, i never used it, so i am just guessing:

    - if you use the spi-auto-generated crc, you cannot "swap" this. It expects an STM32 with same crc unit as target.

    - if you calculate the crc yourself , maybe with the crc unit or just in software, swap bytes, and put it as last value to the send-array , then send all; this should work, if you calculate crc exact in the way, the target expects.