I was wondering how to create a safe UART/USB communication protocol. I need it for the communication between a microcontroller and a PC. I have ~10 commands and thought I'd use 10 separate acknowledge commands for each of them.
The exchange should go like this:
- PC sends wake up command via UART
- µC recognizes that the PC is connected and sends his command to the PC, eg.
- PC does what it was asked to (some hardware stuff) and responds with
~0x01when it's done (I negate the number to create a larger "distance" between the two numbers)
- µC knows that it sent
0x01and is expecting
~0x01from the PC. If something other than
~0x01comes back, the µC will know that something went wrong and will send a new request or an error message
The case that the µC sends
0x01, the PC understands
0x02 and sends
~0x02 back but the µC reads
~0x01 due to some noise would be pretty bad.
How safe is that in terms of transmission, or how can I make this more secure?