How to make use of CRC checks? Or, how to handle CRC failure?

Hi all,

"Big picture" question... I'm working with serial communication between my Arduino and an LCD display. I'm able to compute the CRC just fine. What are some typical ways of actually implementing the use of a CRC check? What do you do when the CRC's don't match?

For example, if I send some data to the display and I check the response for matching CRC's, but they fail, what should I do? Do I have my function automatically repeat itself until I get a good response back? Perhaps I can do that for x number of times before quitting?

I'd love to hear how others implement CRC checks and how you handle them.

Greetings,

jesse214:
What are some typical ways of actually implementing the use of a CRC check?

Communications. That can be across space (send data from here to there) or across time (store this to be retrieved sometime in the future) or both.

What do you do when the CRC's don't match?

Garbage arrived. Discard it. If appropriate, retry.

For example, if I send some data to the display and I check the response for matching CRC's, but they fail, what should I do?

If manipulating the display is important, retry. If the display will be refreshed soon anyway, don't bother.

Do I have my function automatically repeat itself until I get a good response back?

Depends on how important communications is. If you're checking the indoor temperature, which will typically be extremely stable, there is little value in a retry. If you're controlling the fuel flow rate for a jet engine carrying living creatures you keep trying indefinitely.

Perhaps I can do that for x number of times before quitting?

Traditionally, x is three. However, three is a completely arbitrary value. A better choice is to choose x based on the application.

I'd love to hear how others implement CRC checks and how you handle them.

I see CRC failures as an opportunity to hit the boss up for better networking equipment.

If the comms are 2-way you might send an error message back, there are protocols that do that too.

If it's going to keep retrying you might turn a warning light on and/or sound an alarm, even call a phone and/or alert over the internet as one greenhouse automation I know does.

It's very good that you think about error handling. Your code won't be written as if everything always happens as expected.

Hmmm. The "vanilla" form of CRC allows for single bit error correction and double bit error detection. If they've mangled it so badly that it won't do that, what a pity.

Fantastic responses guys! Thank you. Coding Badly, you really gave quite the detailed response. This certainly clears it up for me. My background is in aviation and mechanical engineering, so I appreciate the guidance in a less familiar territory! :wink:

jesse214:
"Big picture" question... I'm working with serial communication between my Arduino and an LCD display. I'm able to compute the CRC just fine. What are some typical ways of actually implementing the use of a CRC check? What do you do when the CRC's don't match?

Fix the hardware used!

I.e. when transferring via Serial-TTL level and the cable is more than one meter when observing CRC error, get yourself Serial-TTL-RS232 adapters for sender and receiver and make sure that the long cable does NOT carry TTL-level signals but RS232 voltage level signals!

You are welcome.

jurs:
Fix the hardware used!

@jesse214, there is an implication from the posts above, including mine, that CRC failures are the result of hardware failures. I want to make certain you understand, that is not necessarily the cause. For example, when trying to communicate using radios CRC failures can be caused by clouds, passing aircraft, electrically noisy vehicles, wind moving an antenna, solar flares, human on the tower, squirrel on the tower, birds, rain, dust, day / night, microwave oven, etcetera.