2020-10-16 05:10 AM
2020-10-16 06:06 AM
I posted some examples in the past, the search is pretty hopeless here
This is an old one, gives a couple of working examples of MODBUS CRC computation
https://community.st.com/s/contentdocument/0690X0000060JWXQA2
https://community.st.com/s/question/0D50X00009XkbNMSAZ/crc-computation
// sourcer32@gmail.com
// 16-Bit CRC of Right Shifting MODBUS Polynomial 0xA001
#include <windows.h>
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
uint16_t Crc16Modbus(uint16_t Crc, uint8_t Data)
{
int i;
Crc = Crc ^ Data;
for(i=0; i<8; i++)
if (Crc & 0x0001)
Crc = (Crc >> 1) ^ 0xA001; // Polynomial used by MODBUS
else
Crc = (Crc >> 1); // Right shifting algorithm
return(Crc);
}
int main(int argc, char **argv)
{
uint8_t TestData[] = { 0x01,0x04,0x75,0x54,0x00,0x02 };
uint16_t crc;
int i;
crc = 0xFFFF; // Initial state
for(i=0; i<sizeof(TestData); i++)
crc = Crc16Modbus(crc, TestData[i]);
printf("CRC = %04X\n", crc);
return(1);
}
http://www.catb.org/~esr/faqs/smart-questions.html#urgent
2020-10-16 07:52 AM
Which STM32?
What did you do?
JW
2020-10-16 08:18 AM
Based on recent postings stm32f103, so needs to be done in software.
Faster methods described in one of attached posts.
2020-10-16 08:56 PM
Thank you