Modbus RTU Standard CRC Format

M

Thread Starter

mp

Hi Everyone,

I developed a Modbus RTU slave in C (windows environment). Is the CRC format [Lobyte] [Hibyte] both in request and answer frame? For calculating the CRC I used the function that is reported on the standard document (Modbus_over_serial_line_V1_02) and the function should return the CRC in the format [Lo][Hi], but when I try the application with a Modbus master simulator (e.g SimplyModbus 6.3.6 or Modscan32) the CRC's that I receive are always swapped comparing to the one calculated from the function. Now, according to the standard, is the function or the simulator wrong! Thanks everyone!

Marcello
 
Hello,

> Is the CRC format [Lobyte] [Hibyte] both in request and answer frame?

Yes.

Right the CRC is calculated. When transmitted it is lo byte then hi byte.

So, the calculated and the transmitted are backwards.

As a slave just include the two bytes, in the order received and the CRC, if good, will be 0.

>...and the function should return the CRC in the format [Lo][Hi]

return (uchCRCHi << 8 | uchCRCLo) ;

I am confused.

Good luck,
Mark
http://www.peakhmi.com/
 
Thank you for the answer.

>>...and the function should return the CRC in the format [Lo][Hi] return (uchCRCHi << 8 | uchCRCLo) ;

So when I calculate the CRC with the function I have to swap the byte before sending it back to the master?

Thanks
Marcello
 
Hello Mark,

yes, it work on both simulator when I swap the byte; on the contrary when I don't swap the byte it doesn't work.

Thanks.
Marcello
 
Top