element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Amphenol
  • Products
  • Manufacturers
  • Amphenol
  • More
  • Cancel
Amphenol
Forum How to do a Double Byte XOR Checksum?
  • Blog
  • Forum
  • Documents
  • Events
  • Leaderboard
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Amphenol to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 23 subscribers
  • Views 5057 views
  • Users 0 members are here
  • checksum
  • data packets
  • serial communication
Related

How to do a Double Byte XOR Checksum?

Sean_Miller
Sean_Miller over 5 years ago

I have a data packet that states its data validation (check code) is verified by a double byte XOR.  I've Googled for a tutorial and came up empty.  I've tried to solve the puzzle in Excel to never get a match to serial data I captured with Putty.  I could use a tip on how the algorithm to apply.

 

The packet description is below.  Starting at position 8, the two byte CS item contains the check code and states it uses a double-byte XOR to verify the current data packet.  I've tried adding up all bytes starting at Si in series which equates to a two byte value.  I XOR it against the CS value I've assed to be xC4AD, but that didn't resolve to 0.

 

Should I be XORing blocks of 2 bytes and comparing to the CS value? 

 

 

image

 

image

 

Example packet:

        

AA 55 00 28 85 AE 9D 0C AD C4 00 00 00 00 00 00 32 00 00 2A 12 59 12 00 00 00 00 A6 1F E5 1F 8D 1F 6D 1F 0A 17 7D 17 62 55 09 1D B1 10 31 10 4D 10 7A 0F 61 0F 5D 0F 21 0F 19 0F 31 0F 49 0F 8D 0F 4E 6D 6D 1D 82 0D 84 0D 00 00 AE 1A 9D 1A 89 1A
  • Sign in to reply
  • Cancel

Top Replies

  • neuromodulator
    neuromodulator over 5 years ago +1
    It might be some parity check. Try to XOR all blocks of 2 bytes and check what you get
  • neuromodulator
    neuromodulator over 5 years ago +1
    Check the last part of the document: http://www.ydlidar.com/Public/upload/files/2019-12-18/YDLIDAR%20X2%20Development%20Manual.pdf It's poorly written, but they say that in case of 3 bytes 1 byte get padded…
  • neuromodulator
    neuromodulator over 5 years ago +1
    Leave the lidar scanning for a while and letme know if you find a checksum error. I suspect thst you wont
Parents
  • Sean_Miller
    Sean_Miller over 5 years ago

    I ported the checksum code posted above to the Arduino and wrote a loop to catch the start of the packet and then parse the entire packet.

     

    Since I never have been one to compile successfully on the first try, I found the checksum comes in handy to catch my bugs and performance issues.  Here you see after every 11th packet read, I finally get a good check.  Of course at these crazy speeds, there is more than enough good data to snag, but I still need to perfect the Arduino code to do better - or address any data transfer problems I might be having from my cables.

     

    -Sean

     

    19:38:56.966 -> Samples Sent:  40 Checksum: 226, 72  New Checksum: 155, 85

    19:38:56.966 -> Samples Sent:  40 Checksum: 187, 108  New Checksum: 22, 106

    19:38:56.966 -> Samples Sent:  40 Checksum: 144, 2  New Checksum: 57, 11

    19:38:56.966 -> Samples Sent:  40 Checksum: 42, 109  New Checksum: 37, 109

    19:38:56.966 -> Samples Sent:  40 Checksum: 202, 76  New Checksum: 202, 76

    19:38:56.966 -> Samples Sent:  40 Checksum: 12, 118  New Checksum: 212, 107

    19:38:56.966 -> Samples Sent:  40 Checksum: 227, 144  New Checksum: 114, 132

    19:38:56.966 -> Samples Sent:  40 Checksum: 137, 64  New Checksum: 235, 93

    19:38:56.966 -> Samples Sent:  40 Checksum: 184, 121  New Checksum: 0, 122

    19:38:56.966 -> Samples Sent:  40 Checksum: 121, 214  New Checksum: 201, 216

    19:38:56.966 -> Samples Sent:  40 Checksum: 111, 127  New Checksum: 78, 98

    19:38:56.966 -> Samples Sent:  40 Checksum: 140, 74  New Checksum: 197, 87

    19:38:56.966 -> Samples Sent:  40 Checksum: 98, 108  New Checksum: 36, 106

    19:38:56.998 -> Samples Sent:  40 Checksum: 217, 15  New Checksum: 116, 10

    19:38:56.998 -> Samples Sent:  40 Checksum: 2, 108  New Checksum: 1, 109

    19:38:56.998 -> Samples Sent:  40 Checksum: 69, 77  New Checksum: 69, 77

    19:38:56.998 -> Samples Sent:  40 Checksum: 208, 118  New Checksum: 148, 107

    19:38:56.998 -> Samples Sent:  40 Checksum: 210, 147  New Checksum: 187, 131

    19:38:56.998 -> Samples Sent:  40 Checksum: 176, 91  New Checksum: 219, 109

    19:38:56.998 -> Samples Sent:  40 Checksum: 229, 105  New Checksum: 217, 97

    19:38:57.023 -> Samples Sent:  40 Checksum: 179, 209  New Checksum: 143, 217

    19:38:57.023 -> Samples Sent:  40 Checksum: 146, 113  New Checksum: 128, 111

    19:38:57.057 -> Samples Sent:  40 Checksum: 184, 72  New Checksum: 57, 84

    19:38:57.057 -> Samples Sent:  40 Checksum: 24, 111  New Checksum: 102, 106

    19:38:57.057 -> Samples Sent:  40 Checksum: 92, 3  New Checksum: 92, 10

    19:38:57.090 -> Samples Sent:  40 Checksum: 239, 111  New Checksum: 108, 109

    19:38:57.090 -> Samples Sent:  40 Checksum: 70, 77  New Checksum: 70, 77

    19:38:57.090 -> Samples Sent:  40 Checksum: 150, 64  New Checksum: 76, 93

    19:38:57.090 -> Samples Sent:  40 Checksum: 96, 174  New Checksum: 207, 128

    19:38:57.123 -> Samples Sent:  40 Checksum: 66, 125  New Checksum: 137, 112

    19:38:57.123 -> Samples Sent:  40 Checksum: 14, 0  New Checksum: 234, 102

    19:38:57.123 -> Samples Sent:  40 Checksum: 159, 201  New Checksum: 147, 151

    19:38:57.156 -> Samples Sent:  40 Checksum: 192, 64  New Checksum: 114, 90

    19:38:57.156 -> Samples Sent:  40 Checksum: 8, 72  New Checksum: 25, 85

    19:38:57.156 -> Samples Sent:  40 Checksum: 201, 117  New Checksum: 204, 112

    19:38:57.189 -> Samples Sent:  40 Checksum: 161, 14  New Checksum: 115, 10

    19:38:57.189 -> Samples Sent:  40 Checksum: 36, 75  New Checksum: 56, 75

    19:38:57.189 -> Samples Sent:  40 Checksum: 255, 77  New Checksum: 255, 77

    19:38:57.189 -> Samples Sent:  40 Checksum: 86, 70  New Checksum: 250, 88

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Sean_Miller
    Sean_Miller over 5 years ago

    I ported the checksum code posted above to the Arduino and wrote a loop to catch the start of the packet and then parse the entire packet.

     

    Since I never have been one to compile successfully on the first try, I found the checksum comes in handy to catch my bugs and performance issues.  Here you see after every 11th packet read, I finally get a good check.  Of course at these crazy speeds, there is more than enough good data to snag, but I still need to perfect the Arduino code to do better - or address any data transfer problems I might be having from my cables.

     

    -Sean

     

    19:38:56.966 -> Samples Sent:  40 Checksum: 226, 72  New Checksum: 155, 85

    19:38:56.966 -> Samples Sent:  40 Checksum: 187, 108  New Checksum: 22, 106

    19:38:56.966 -> Samples Sent:  40 Checksum: 144, 2  New Checksum: 57, 11

    19:38:56.966 -> Samples Sent:  40 Checksum: 42, 109  New Checksum: 37, 109

    19:38:56.966 -> Samples Sent:  40 Checksum: 202, 76  New Checksum: 202, 76

    19:38:56.966 -> Samples Sent:  40 Checksum: 12, 118  New Checksum: 212, 107

    19:38:56.966 -> Samples Sent:  40 Checksum: 227, 144  New Checksum: 114, 132

    19:38:56.966 -> Samples Sent:  40 Checksum: 137, 64  New Checksum: 235, 93

    19:38:56.966 -> Samples Sent:  40 Checksum: 184, 121  New Checksum: 0, 122

    19:38:56.966 -> Samples Sent:  40 Checksum: 121, 214  New Checksum: 201, 216

    19:38:56.966 -> Samples Sent:  40 Checksum: 111, 127  New Checksum: 78, 98

    19:38:56.966 -> Samples Sent:  40 Checksum: 140, 74  New Checksum: 197, 87

    19:38:56.966 -> Samples Sent:  40 Checksum: 98, 108  New Checksum: 36, 106

    19:38:56.998 -> Samples Sent:  40 Checksum: 217, 15  New Checksum: 116, 10

    19:38:56.998 -> Samples Sent:  40 Checksum: 2, 108  New Checksum: 1, 109

    19:38:56.998 -> Samples Sent:  40 Checksum: 69, 77  New Checksum: 69, 77

    19:38:56.998 -> Samples Sent:  40 Checksum: 208, 118  New Checksum: 148, 107

    19:38:56.998 -> Samples Sent:  40 Checksum: 210, 147  New Checksum: 187, 131

    19:38:56.998 -> Samples Sent:  40 Checksum: 176, 91  New Checksum: 219, 109

    19:38:56.998 -> Samples Sent:  40 Checksum: 229, 105  New Checksum: 217, 97

    19:38:57.023 -> Samples Sent:  40 Checksum: 179, 209  New Checksum: 143, 217

    19:38:57.023 -> Samples Sent:  40 Checksum: 146, 113  New Checksum: 128, 111

    19:38:57.057 -> Samples Sent:  40 Checksum: 184, 72  New Checksum: 57, 84

    19:38:57.057 -> Samples Sent:  40 Checksum: 24, 111  New Checksum: 102, 106

    19:38:57.057 -> Samples Sent:  40 Checksum: 92, 3  New Checksum: 92, 10

    19:38:57.090 -> Samples Sent:  40 Checksum: 239, 111  New Checksum: 108, 109

    19:38:57.090 -> Samples Sent:  40 Checksum: 70, 77  New Checksum: 70, 77

    19:38:57.090 -> Samples Sent:  40 Checksum: 150, 64  New Checksum: 76, 93

    19:38:57.090 -> Samples Sent:  40 Checksum: 96, 174  New Checksum: 207, 128

    19:38:57.123 -> Samples Sent:  40 Checksum: 66, 125  New Checksum: 137, 112

    19:38:57.123 -> Samples Sent:  40 Checksum: 14, 0  New Checksum: 234, 102

    19:38:57.123 -> Samples Sent:  40 Checksum: 159, 201  New Checksum: 147, 151

    19:38:57.156 -> Samples Sent:  40 Checksum: 192, 64  New Checksum: 114, 90

    19:38:57.156 -> Samples Sent:  40 Checksum: 8, 72  New Checksum: 25, 85

    19:38:57.156 -> Samples Sent:  40 Checksum: 201, 117  New Checksum: 204, 112

    19:38:57.189 -> Samples Sent:  40 Checksum: 161, 14  New Checksum: 115, 10

    19:38:57.189 -> Samples Sent:  40 Checksum: 36, 75  New Checksum: 56, 75

    19:38:57.189 -> Samples Sent:  40 Checksum: 255, 77  New Checksum: 255, 77

    19:38:57.189 -> Samples Sent:  40 Checksum: 86, 70  New Checksum: 250, 88

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube