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.
0x01
- PC does what it was asked to (some hardware stuff) and responds with
~0x01
when it's done (I negate the number to create a larger "distance" between the two numbers) - µC knows that it sent
0x01
and is expecting~0x01
from the PC. If something other than~0x01
comes 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?