Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 341 of 9365. Communication Protocols and Data TransferFree lesson

Calculating Baud Rate and Bit Duration

Learners will calculate the relationship between baud rate and bit duration to ensure timing compatibility between two communicating embedded devices.

Calculating Baud Rate and Bit Duration

In this lesson, you will learn how to calculate the precise timing relationship between baud rate and bit duration to ensure two embedded devices can "speak" the same language.

The Relationship Between Time and Speed

In asynchronous serial communication, the baud rate represents the number of signal transitions (symbols) that occur per second. Because each bit is sent for a fixed period of time, we call this the bit duration (or bit period). The two are inversely proportional:

Bit Duration (seconds) = 1 / Baud Rate (bits per second)

If you are communicating at a standard baud rate like 9600 bps, the duration of a single bit is 1 / 9600 ≈ 104.17 microseconds. If your peripheral's clock timing drifts away from this value, the receiver will sample the data line at the wrong moment, leading to framing errors and corrupted data.

Practical Calculation

When configuring a UART peripheral, you often need to set a prescaler or a divider based on your system clock frequency (f_clk). The formula typically looks like this:

Baud Rate = f_clk / (8 * (2 - OVER8) * USARTDIV)

However, at the fundamental level, you are simply asking: "How many clock cycles fit into one bit duration?"

If your system clock is 16 MHz and you want a baud rate of 9600, your calculation would look like this:

// Example: Calculating ticks per bit
uint32_t system_clock = 16000000; // 16 MHz
uint32_t baud_rate = 9600;
uint32_t clock_ticks_per_bit = system_clock / baud_rate;

// If we need 104.17 microseconds per bit:
// 16,000,000 / 9600 = 1666.67 clock cycles per bit

Why Precision Matters

Asynchronous communication relies entirely on timing because there is no shared clock line (unlike the synchronous mechanisms we discussed previously). Both the sender and the receiver must agree on the bit duration before the start bit arrives. If your calculation is off by even a small percentage, the cumulative drift over a single 8-bit frame will cause the receiver to sample the stop bit or the next start bit incorrectly.

Key Takeaway: The bit duration is the mathematical inverse of the baud rate; precise calculation of this interval is the only way to prevent sampling errors in asynchronous serial communication.