first of all, thanks for sharing your work and knowledge.
I am intending to make a communication protocol based on your serial RS 485 implementation, which I think is straightforward and uses only what is really needed. I think it indicates good code when everyone would say something like "this is easy, of course this is how you do it".
I have had a look at the code and already done a basic implementation.
Since I would like to eliminate possible errors I have a question concerning the switch case which handles the incoming bytes (or more specific the available bytes in the receive buffer).
1: if the incoming Data is another STX or ETX it counts as a valid STX or ETX - of course there will probably be an error afterwards because of a non-valid CRC, but maybe it would make sense to produce an error, if another STX or ETX is in the buffer before a valid CRC is received indicating the end of this message.
2: connected to this is the problem, that the CRC Code itself might be recognized as a wrong STX or ETX which will lead to a mysterious error (or am I missing something?)
Thanks and regards,
Markus