Challenge - 5 Problems
Baud Rate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Calculate UBRR value for 16 MHz clock and 9600 baud
Given a CPU clock of 16 MHz and a desired baud rate of 9600, what is the UBRR register value calculated by the formula UBRR = (F_CPU / (16 * BAUD)) - 1?
Embedded C
unsigned int ubrr = (16000000 / (16 * 9600)) - 1; printf("%u", ubrr);
Attempts:
2 left
💡 Hint
Use integer division carefully and subtract 1 after dividing.
✗ Incorrect
The formula for UBRR is (F_CPU / (16 * BAUD)) - 1. Plugging in 16,000,000 and 9600 gives 103.1666, which truncates to 103.
❓ Predict Output
intermediate2:00remaining
Effect of double speed mode on UBRR calculation
If the UART double speed mode (U2X) is enabled, the baud rate formula changes to UBRR = (F_CPU / (8 * BAUD)) - 1. What is the UBRR value for 16 MHz clock and 115200 baud with U2X enabled?
Embedded C
unsigned int ubrr = (16000000 / (8 * 115200)) - 1; printf("%u", ubrr);
Attempts:
2 left
💡 Hint
Remember to divide by 8 instead of 16 when U2X is set.
✗ Incorrect
With U2X enabled, the divisor is 8 instead of 16. So UBRR = (16000000 / (8 * 115200)) - 1 = 16.36, truncated to 16.
🔧 Debug
advanced2:00remaining
Identify the error in baud rate calculation code
What error does the following code produce when compiled and run?
unsigned int ubrr = 16000000 / 16 * 9600 - 1;
printf("%u", ubrr);
Embedded C
unsigned int ubrr = 16000000 / 16 * 9600 - 1; printf("%u", ubrr);
Attempts:
2 left
💡 Hint
Check the order of operations in the expression carefully.
✗ Incorrect
The expression divides 16000000 by 16, then multiplies by 9600, which is not the intended formula. The correct formula divides by (16 * 9600).
🧠 Conceptual
advanced2:00remaining
Why is the UBRR value subtracted by 1 in the baud rate formula?
In the baud rate calculation formula UBRR = (F_CPU / (16 * BAUD)) - 1, why do we subtract 1 from the division result?
Attempts:
2 left
💡 Hint
Think about how hardware counters usually start counting.
✗ Incorrect
The UBRR register sets the baud rate divisor and counts from zero, so subtracting 1 adjusts the value to match the desired baud rate.
❓ Predict Output
expert3:00remaining
Calculate baud rate error percentage
Given F_CPU = 8 MHz, desired baud rate = 19200, and UBRR calculated as 25 using formula UBRR = (F_CPU / (16 * BAUD)) - 1, what is the baud rate error percentage?
Use actual baud rate = F_CPU / (16 * (UBRR + 1)) and error% = ((actual - desired) / desired) * 100
Embedded C
unsigned int ubrr = 25; float actual_baud = 8000000.0 / (16 * (ubrr + 1)); float error = ((actual_baud - 19200) / 19200) * 100; printf("%.2f", error);
Attempts:
2 left
💡 Hint
Calculate actual baud rate first, then find percentage difference.
✗ Incorrect
Actual baud = 8000000 / (16 * 26) = 19230.77. Error = ((19230.77 - 19200)/19200)*100 ≈ 0.16%. The code outputs "0.16".