UART CRC with MODBUS-RTU

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello everybody,

   

I implemented on Psoc3 a signal conditioning with a Modbus-RTU interface (it's works well since 1 year). The CRC is checked by software. I would like to upgrade this application and to generate the CRC by  hardware  instead of  software but I don't succed it, the CRC is always wrong. I just made this little test (enclose) to check the CRC...If someone has already implemented the same interface(Modbus-RTU with hardware CRC)??

9 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The reset signal of the CRC-component is synchronus to clock, so there must be a reset while a clock pulse comes. The clock pulse will come only while receiving a byte from UART, so there will be at least one bit missing in the CRC.

   

Since CRC is mostly used to ensure transmission of several bytes(messages) I would suggest to use the Start() and Stoip() APIs to clear the CRC-component.

   

Another point would be: You have a loop-delay which will be completely unsynchronus to the receiving baud-rate, CRC-generation can be in the middle of a byte, no exact result possibe.

   

You declared a local loop-variable as "volatile" which is not needed, but you forgot to declare your global "nb"-variable as "volatile" because this is changed in an interrupt handler.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.

Hi Bob,

I understand that it is necessary to create some logic between UART and CRC components. But i can't set CRC componet up for calculating Modbus RTU CRC. I just slightly change the CRC example project by changing Polynomial Value to 0xA001 and seed value to 0xFFFF, but CRC output does not meet with expected result.

Coud you please give me advice how to right configure CRC component?

My testing confiration you could find in attachment.

Thank you.

Jan

0 Likes

My working CRC configuration for Modbus RTU is folowing:

Polynomial value - 0xC002

Seed value - 0xFFFF

Data in - LSB first

result is in format LSB->MSB.

For HW CRC calculation is necessary put 16bit shift register between UART tx_data and CRC di and add simply verilog component that holding CRC component in reset during first 16bits.

I tested HW Rx CRC calculation until maximal uart baud rate 921600 baud/s.

Jan

0 Likes
Anonymous
Not applicable

Hi Bob,

   

Thanks for you fast answer.

   

I make the modification that you provide me and made some new test... In the same time, I received an answer from the technical support concerning the CRC in modbus and I can't use it for an external device (in may case IHM) so the only way to check the CRC is by software.

0 Likes

Olivier, please contact me as soon as you can, have proposal might interest you. Thanks!

0 Likes
Anonymous
Not applicable

Hi Oliver,

   

I am interested in your Modbus-RTU implementation, would it be possible to email me the component or project?

   

Yungky

0 Likes
EdUc_284901
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

Very interesting Olivier. Does it work 100% right?? If so, please contact me via email cause I'm planning to use it on the psoc 5lp platform

0 Likes
Anonymous
Not applicable

Hi Oliver

   

I am looking for MODBUS-RTU slave for PSoC 5lp wonder if we can cooperate on that

   

Thanks

0 Likes
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

Perhaps you want a simple version : PSoC5LP_ModbusSlave.zip
http://mylab.wmsite.ru/ftpgetfile.php?id=140
 (  PSoC4CY8CKIT-059 PSoC 5LP /  PSoC Creator 3.3 ) 
It here (Russian):   http://mylab.wmsite.ru/moi-razrab/cypress-psoc/modbus/

0 Likes