It could be that the checksum adds to a control character, such as the 'start of message' or 'end of message' byte, or the message contains a value equal to a control character. This could be a checksum or a CRC error or something else. If the message can be corrupted we need some error checking. In your example, ^, in binary protocols often 0x02 To get around this you have a start of message sequence. For example, if the Arduino just woke from sleep there might be some garbage in the serial buffer. These bytes would then be prefixed to the message and cause it to be interpreted wrongly. The problem with just having end of message is that you don't know what other bytes have already been received when you send your message. Binary protocols might use 0x03 or some other common byte. The simplest ASCII protocols just have an end of message character sequence, often \r or \n as this is what gets printed when the enter key is hit. Some of the common things you see in point to point protocols are: There are a lot of ways to write a serial protocol depending on what functionality you might want and how much error checking you need.
0 Comments
Leave a Reply. |