This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

about serial communication baud rate

If we set different baud rates in an master-slave system,can the system work correctly?!thank you!

Parents
  • Because the receiver only detects the first flank of the start bit of a byte.

    Then the receiver counts fixed time based on the configured baudrate, to decide where to sample the bits in the byte.

    Only when the receiver has an almost perfect baudrate will it manage to sample the bits at the correct position, reproducing the transmitted byte.

    Connect two PC together, and set them to different baudrate and try to communicate. Notice the strange characters you will see on the receiver side? It does detect transitions and decides that it sees start bits. Then it will either sample too slow (continue way past the stop bit(s)) or too fast, being done way before the stop bit(s).

    It is only when performing an auto-detect that the receiver (hardware or software) tries to perform either higpseed sampling of the bits, or measure the times between multiple flanks, to figure out the baudrate. That is also why protocols that has autobaud support normally starts with some specific bytes to make sure that the sent bytes has a good pattern for auto-detect.

    The uart does a check for existence of a stop bit after having counted through all data bits and an optional parity bit. But if there is no stop bit found, the uart will not know if this was caused by an incorrect baudrate or if it detected a false start bit. All you know is that if you get a lot of parity errors or framing errors (missing stop bit), the probability is high that you have the wrong baudrate. It could also be the result of a too long cable and bad signal integrity.

Reply
  • Because the receiver only detects the first flank of the start bit of a byte.

    Then the receiver counts fixed time based on the configured baudrate, to decide where to sample the bits in the byte.

    Only when the receiver has an almost perfect baudrate will it manage to sample the bits at the correct position, reproducing the transmitted byte.

    Connect two PC together, and set them to different baudrate and try to communicate. Notice the strange characters you will see on the receiver side? It does detect transitions and decides that it sees start bits. Then it will either sample too slow (continue way past the stop bit(s)) or too fast, being done way before the stop bit(s).

    It is only when performing an auto-detect that the receiver (hardware or software) tries to perform either higpseed sampling of the bits, or measure the times between multiple flanks, to figure out the baudrate. That is also why protocols that has autobaud support normally starts with some specific bytes to make sure that the sent bytes has a good pattern for auto-detect.

    The uart does a check for existence of a stop bit after having counted through all data bits and an optional parity bit. But if there is no stop bit found, the uart will not know if this was caused by an incorrect baudrate or if it detected a false start bit. All you know is that if you get a lot of parity errors or framing errors (missing stop bit), the probability is high that you have the wrong baudrate. It could also be the result of a too long cable and bad signal integrity.

Children
  • Addendum - the slave is not an oscilloscope that runs at an extremely high sampling rate to sample a nice-looking curve.

    The normal design is that the receiver runs at 16 times the baudrate. It then takes 3 samples in the middle of each bit window and does a majority vote to decide if it's a one or a zero. If the baudrate is slightly off, this sampling window will drift so the receiver may sample during the transition between two bits. Or it may perform two sets of reads while the transmitter is still on the same bit, in case the receiver has too low baudrate.

    Remember that the data transmitted may not toggle the data on every bit windw - you may have one start bit followed by four data bits of same polarity as the start bit. Then four data bits with the same polarity as the stop bit(s). If you didn't know the baudrate but just looked at the scope image - exactly what would you think about that square wave? How would a receiver compensate to make sense of it?

    The baudrate is a "common secret" that the transmitter and receiver must agree on to get the communicatin working. It is possible to transmit test patterns and have the receiver autodetect. But you will have to write code for the autodetect unless you have a processor with hw autodetect. And you do need the test pattern - if you autodetect on live data, then one or more bytes will have been lost before the autodetect is done.

    A modem can autodetect on the "AT" characters.

    How will slaves autodetect when you have one master and multiple slaves and different slaves have different baudrate? Whenever you switch to talk to another slave, the baudrate may change - so the slave must either hope that the master returns later with the same baudrate, or it will have to retrain continuously - remember that the slave must be able to pick up protocol data to figure out the message address so it knows if it should care about the message or not.

    Now, exactly why are you pushing this concept, in the first place?