3/10/2020 2:08 PM | |
Joined: 10/31/2018 Last visit: 8/16/2024 Posts: 26 Rating: (0) |
Hi All I'm trying to get the LGF_CRC16 to work in a project, and it keeps giving the wrong CRC compared to the Sunshine2k calculator. Is there a reason it does not work for Modbus? Regards Alan ------------------------------------------------------------------------------------------ |
Last edited by: The Helping Hand at: 03/10/2020 17:21:07New subject after splitting |
|
3/10/2020 2:55 PM | |
Joined: 4/11/2012 Last visit: 9/6/2024 Posts: 181 Rating: (34) |
Some steps you can take to narrow the issue:
|
This contribution was helpful to1 thankful Users |
3/11/2020 10:12 AM | |
Joined: 10/31/2018 Last visit: 8/16/2024 Posts: 26 Rating: (0) |
Second attachment |
3/11/2020 11:12 AM | |
Joined: 4/11/2012 Last visit: 9/6/2024 Posts: 181 Rating: (34) |
I checked the LGF_CRC16 now. There are multiple ways to do the CRC calculation and I have only used one. But the method used in the LGF_CRC16 library seems to be fully opposite to the method I have used. It shifts Left? I have used the CRC calculation method defined in Modbus documentation. Check attachment or the document linked below. The Poly defined in that document is 0xA001, and this leads us to the Wikipedia article: https://en.wikipedia.org/wiki/Cyclic_redundancy_check#Polynomial_representations_of_cyclic_redundancy_checks There it can be seen that each CRC calculation has different Polynomial, but the Poly can be Normal or Reversed. CRC-16-IBM (used by modbus) Normal poly is 0x8005 but Reversed poly is 0xA001. The Modbus specification uses the 0xA001 Poly, so the Reversed poly. With that Poly and with shift right (instead of left) the CRC calculation works. I can't help further with the LGF_CRC16 function. I have created my own CRC calculation function using the Modbus CRC calculation diagram. (I even created a separate CRC calculation to safety program using that diagram.) |
This contribution was helpful to1 thankful Users |
Follow us on