reliable Serial protocol - Selfmade

Hi

I'm currently programming on a project, i also would add setting parameters via Serial.

For this i need to transfer a control command like [LED] or [CLR] and value as well [0xFF] and sometimes multiple values like [0x00] [0x55] .....

I now that most serial devices have a protocol that is 'failsafe' which means there is also a byte for the length of the telegram in case of [LED] [0x00] [0x01] [0x02] that lenght-byte would be 3. And then there is also some kind of a calculated value called CVC or something, but i'm not sure if that is needed or helpful.

My Question is, does someone knows a nice tutorial about this, and can it even be done?

The phrase that you are looking for is Cyclic Redundancy Check or CRC for short and, yes, it can be done. There are even Arduino libraries for it.

Mr. Google will find you plenty of information and for general information on Serial data transfer using an Arduino have a look at Serial input basics - updated

Optomux and Modbus are good examples.

Somewhere on this forum is a list of protocol elements and what purpose they serve. If I can find my old post I will provide a link.

CRC is definitely the best choice for error detection.

https://forum.arduino.cc/index.php?topic=390336.msg2688993#msg2688993

This may have something of value...
http://forum.arduino.cc/index.php?topic=198448.0

sgt_johnny:
Hi

I'm currently programming on a project, i also would add setting parameters via Serial.

For this i need to transfer a control command like [LED] or [CLR] and value as well [0xFF] and sometimes multiple values like [0x00] [0x55] .....

I now that most serial devices have a protocol that is 'failsafe' which means there is also a byte for the length of the telegram in case of [LED] [0x00] [0x01] [0x02] that lenght-byte would be 3. And then there is also some kind of a calculated value called CVC or something, but i'm not sure if that is needed or helpful.

My Question is, does someone knows a nice tutorial about this, and can it even be done?

I spent years programming such protocols and suggest you REALLY think about the need for CRCs and the associated error recovery software. Are you using two Arduinos to communicate over a short distance with real copper wires between them? If so, you will probably never see an error. How will you communicate an error discovery from one Arduino to the other? Will the error cause a retransmission and how many times? How will you handle the situation when the number of retransmissions is exceeded? Will you have some facility to restart the communications after that number is exceeded? Are you going to have the receiving Arduino acknowledge the good message? If not, why have CRCs?

An easier protocol might be to number your transmissions and send them 3 times, with the receiver ignoring any errors found, and using only one of the three transmissions if it is good.

Paul

Paul_KD7HB:
I spent years programming such protocols and suggest you REALLY think about the need for CRCs and the associated error recovery software. Are you using two Arduinos to communicate over a short distance with real copper wires between them? If so, you will probably never see an error. How will you communicate an error discovery from one Arduino to the other? Will the error cause a retransmission and how many times? How will you handle the situation when the number of retransmissions is exceeded? Will you have some facility to restart the communications after that number is exceeded? Are you going to have the receiving Arduino acknowledge the good message? If not, why have CRCs?

An easier protocol might be to number your transmissions and send them 3 times, with the receiver ignoring any errors found, and using only one of the three transmissions if it is good.

Paul

Some flavours of CRC facilitate automatic error correction. Then a retransmission protocol is unnecessary.

aarg:
Some flavours of CRC facilitate automatic error correction. Then a retransmission protocol is unnecessary.

True for high value transmissions. Don't know what the OP has in mind.

Paul

A painless way for a beginner to "roll their own" message verification, is a simple checksum.

Send the message, return the message, if it was returned properly, send an OK

.