I am writing some code for a microprocessor to communicate with an external device via asynchronous serial communication over a single wire.
I can recognize a transition on the wire from low/high (either way), so I can find the bit boundaries. Given that I know the baud rate the device is using I can then start clocking off bits, so I can read the stream of bits coming from the device.
What I’m struggling with conceptually is recognizing a start bit – finding the start of a byte frame (assuming I’m getting 8 bit, no parity, 1 start bit, 1 stop bit). I understand that each frame begins with a start bit and ends with a stop bit, but it is my understanding that start and stop bits look like any other bits – so there’s nothing special about them that identifies them as start or stop bits (other than their position).
The only way I can think of to identify a start bit is that it will be the first high bit after a sustained idle period – that is, since I’m expecting 8 bits no parity, if I get 9 or more low bits then the line is idle, and the next high bit will be a start bit. That’s all fine, but what if I start listening to the device mid-bitstream and there is no idle time of 9 bits or more on the wire? I am clocking off bits, but how do I recognize which bit is a start bit so I can read off a byte? If I’m clocking off bits, then anything in between frames can only be integer multiples of bits (so a stop “bit” can’t be 1.5 bits for example), so everything just looks like bits.
I hope I’m making sense… thanks for any help.
The start bit is what gets your code to receive a byte going. Best explained with a state machine. You’ve got 4 basic states:
So basic insights from this is that you need the start bit to get the code going that receives a byte. And that the stop bit is important so you can reliably see the start bit for the next byte.