Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    crcmod

    Scheduled Pinned Locked Moved MicroPython
    4 Posts 2 Posters 1.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      gertjanvanhethof Pybytes Beta
      last edited by

      Does somebody know if there is an implementation of crcmod available for mircopython?
      I need to calculate crc for 16bits values.

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        Shaun @gertjanvanhethof
        last edited by

        @gertjanvanhethof
        This is my CRC16 function based on a very common CRC16 method.
        Perhaps it will help you.
        You may need to change the seed value to 0x0000, depending on what CRC16 you are hoping to implement

        def crc16Nib (data):
        CRC16_TBL_SML = ([0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400,])
        crc = 0xFFFF # 0xFFFF seeded
        for x in data:
        crc = CRC16_TBL_SML[(x ^ crc) & 0x0F] ^ (crc >> 4) # because using the reflected algorithm, the low nibble is processed first
        crc = CRC16_TBL_SML[((x >> 4) ^ crc) & 0x0F] ^ (crc >> 4)
        return crc;

        1 Reply Last reply Reply Quote 0
        • G Offline
          gertjanvanhethof Pybytes Beta
          last edited by

          Thxs for you answer.

          Do you also hava a CRC8 function which is able to do the following?

          Name: CRC-8
          Width: 8 bit
          Polynomial 0x31 (x8 + x5 + x4 + 1)
          Initialization 0xFF
          Final XOR: 0x00
          Examples: CRC (0xBEEF) = 0x92

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            Shaun @gertjanvanhethof
            last edited by

            @gertjanvanhethof

            I have a DALLAS 1Wire implementation.

            I'm sure you can find look up values to change it to the CRC8 you require.

            def crc8Nib (data):
            #'''
            CRC8_TABLE_SML1 = bytes([0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41])
            CRC8_TABLE_SML2 = bytes([0x00, 0x9d, 0x23, 0xbe, 0x46, 0xdb, 0x65, 0xf8, 0x8c, 0x11, 0xaf, 0x32, 0xca, 0x57, 0xe9, 0x74])
            #'''
            try:
            crc = 0xFF # 0xFF seeded
            for x in data:
            t = (x ^ crc) & 0xFF
            crc = CRC8_TABLE_SML1[t & 0x0f] ^ CRC8_TABLE_SML2[t >> 4]
            return crc;
            except ValueError:
            pass

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom