hi,
i am fresher to this stm32 , i am doing project on modbus but i am not able to calculate crc value and i am not getting what i need to add to my code to calculate crc in modbus . can anyone help me its urgent.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-10-16 5:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-10-16 6: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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-10-16 7:52 AM
Which STM32?
What did you do?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-10-16 8:18 AM
Based on recent postings stm32f103, so needs to be done in software.
Faster methods described in one of attached posts.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-10-16 8:56 PM
Thank you
