The start bit tells the receiver that it is about to receive a byte and should interpret the next ones as data bits. The stop bit is a very basic error check to detect a baudrate or byte length mismatch. Not every serial communication protocol uses them, a synchronous protocol like SPI doesn't.
1) The data sent through serial have one start and stop bit and is the hex "7E". The device uses a request/response protocol, so the Arduino board must send the data in order to receive something.
1 and if you have two stop bits instead of one, then again the pattern has to match to call it a good character, start bit, n data bits and two stop bits. The use of the start and stop bit is to find the byte/word boundaries within a serial stream.
The start and stop bits are used in asynchronous communication as a means of timing or synchronizing the data characters being transmitted. The start bit is used to signal the beginning of a frame.
The whole collection of bits is a packet if you will. the start and stop bits are otherwise indistinguishable from data bits. Say for example you have one start bit, one stop bit, no parity and 8 data bits. That means there is a low bit (start) 8 data bits (can be any one of the 256 combinations) and high bit (stop). The receiver has to be told that this is 8N1 so it is looking for a low, 8 bits and a high, if it doesnt see that then it is not locked on the data, and most likely it basically discards the first bit, shifts in one more, then looks for a start and stop with 8 in the middle. Once it sees that then it assumes it is real data and allows the byte/character in to the receive buffer. If the next 10 bits dont have that start 8 bits stop pattern, then that is a framing error and it starts searching again. so if this pattern comes in
000000000000011111
the first 10 bits do not have a start and stop
0000000000
so discard the first zero and try again
00000000000011111
0000000000
nope, still no start and stop
this repeats until the serial stream shifting in looks like this
00000000011111xxxxxxxxxxx
0000000001
we have a start, 8 bits and a stop, so we consider that a good character 0x00 save 0x00 in the rx buffer.
starting with the next bit after the stop bit we take the next 10
1111xxxxxxxxxxx
and that does not start with a start bit, so that is a framing error
1111xxxxxx
we go back to searching for a start bit 8 bits and a stop bit.
if you use a parity bit then it is the same but not only do you need a start and stop, but you need the bits in the middle to have a certain parity, even or odd. so to get a good character you need start, some number of bits with the correct parity and a stop bit, then you can extract the character and start after the stop bit looking for another start bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With