Bird
Raised Fist0
Embedded Cprogramming~20 mins

UART protocol fundamentals in Embedded C - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
UART Protocol Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
UART Transmission Bit Timing Calculation
Given a UART baud rate of 9600 and a system clock of 16 MHz, what is the value of the UART bit time in microseconds calculated by the code below?
Embedded C
unsigned int baud_rate = 9600;
unsigned long clock_freq = 16000000;
float bit_time_us = (1.0 / baud_rate) * 1000000;

// Print bit time
printf("%.2f\n", bit_time_us);
A16.00
B9600.00
C104.17
D1.60
Attempts:
2 left
💡 Hint
Remember that bit time is the inverse of baud rate, converted to microseconds.
❓ Predict Output
intermediate
1:30remaining
UART Frame Size Calculation
What is the total number of bits transmitted in one UART frame with 1 start bit, 8 data bits, no parity, and 1 stop bit?
A10
B9
C11
D8
Attempts:
2 left
💡 Hint
Add start bits, data bits, parity bits (if any), and stop bits.
🔧 Debug
advanced
2:30remaining
Identify the UART Configuration Error
The following UART initialization code is intended to set 8 data bits, even parity, and 1 stop bit. Which option correctly identifies the error causing wrong parity configuration?
Embedded C
UART_Config config;
config.data_bits = 8;
config.parity = 0; // 0 means no parity
config.stop_bits = 1;
UART_Init(&config);
AData bits should be set to 7 for even parity to work.
BParity is set to 0 which disables parity; should be set to 2 for even parity.
CStop bits must be 2 for parity to be enabled.
DUART_Init function is missing baud rate parameter.
Attempts:
2 left
💡 Hint
Check the parity value and what it represents.
📝 Syntax
advanced
1:30remaining
UART Interrupt Handler Syntax
Which option shows the correct syntax for a UART receive interrupt handler function in embedded C?
Avoid UART_RX_IRQHandler(void) { /* handle RX interrupt */ }
BUART_RX_IRQHandler(void) { /* handle RX interrupt */ }
Cvoid UART_RX_IRQHandler(int irq) { /* handle RX interrupt */ }
Dint UART_RX_IRQHandler() { /* handle RX interrupt */ }
Attempts:
2 left
💡 Hint
Interrupt handlers usually return void and take no parameters.
🚀 Application
expert
3:00remaining
UART Data Buffer Overflow Scenario
In a UART communication system, if the receive buffer is not read fast enough and new data keeps arriving, what will happen?
AThe UART will store all data indefinitely without loss.
BThe UART hardware will automatically pause transmission until buffer is free.
CThe system will raise a hardware exception and reset the UART module.
DNew incoming data will overwrite old unread data causing data loss.
Attempts:
2 left
💡 Hint
Think about what happens when a fixed-size buffer is full and new data arrives.

Practice

(1/5)
1. What does UART stand for in embedded systems communication?
easy
A. Universal Analog Radio Transmitter
B. Universal Automatic Register Transfer
C. Unified Asynchronous Remote Terminal
D. Universal Asynchronous Receiver/Transmitter

Solution

  1. Step 1: Understand UART acronym

    UART is a communication protocol used in embedded systems for serial communication.
  2. Step 2: Match full form

    UART stands for Universal Asynchronous Receiver/Transmitter, describing its function.
  3. Final Answer:

    Universal Asynchronous Receiver/Transmitter -> Option D
  4. Quick Check:

    UART = Universal Asynchronous Receiver/Transmitter [OK]
Hint: Remember UART is about asynchronous serial communication [OK]
Common Mistakes:
  • Confusing UART with synchronous protocols
  • Mixing up the acronym words
  • Thinking UART is analog communication
2. Which of the following is the correct way to initialize UART in embedded C?
easy
A. uart_init(9600);
B. UART_Init(baudrate=9600);
C. uartStart(9600);
D. init_uart(9600);

Solution

  1. Step 1: Identify common UART init function

    In embedded C, uart_init with baud rate parameter is a common initialization call.
  2. Step 2: Check syntax correctness

    uart_init(9600); uses correct function name and parameter style without extra keywords.
  3. Final Answer:

    uart_init(9600); -> Option A
  4. Quick Check:

    Correct UART init syntax = uart_init(9600); [OK]
Hint: Look for simple function call with baud rate only [OK]
Common Mistakes:
  • Using incorrect function names
  • Adding parameter names inside call
  • Using camelCase instead of snake_case
3. What will be the output of this UART send code snippet?
uart_init(9600);
uart_send_char('A');
uart_send_char('B');
medium
A. BA
B. A B
C. AB
D. Error: uart_send_char undefined

Solution

  1. Step 1: Initialize UART at 9600 baud

    The uart_init(9600) sets baud rate for communication.
  2. Step 2: Send characters in order

    uart_send_char('A') sends 'A', then uart_send_char('B') sends 'B' sequentially.
  3. Final Answer:

    AB -> Option C
  4. Quick Check:

    Characters sent in order = AB [OK]
Hint: Characters send in call order, no spaces added [OK]
Common Mistakes:
  • Assuming characters reverse order
  • Expecting spaces between characters
  • Thinking uart_send_char is undefined
4. Identify the error in this UART initialization code:
void setup() {
  uart_init(115200);
  uart_init(9600);
}
medium
A. uart_init requires no parameters
B. Multiple uart_init calls cause baud rate conflict
C. Function name should be UART_Init
D. No error, code is correct

Solution

  1. Step 1: Review uart_init calls

    Two uart_init calls with different baud rates cause conflict in configuration.
  2. Step 2: Understand UART config rules

    UART baud rate must be set once before communication; multiple calls overwrite settings.
  3. Final Answer:

    Multiple uart_init calls cause baud rate conflict -> Option B
  4. Quick Check:

    Multiple init calls cause conflict = A [OK]
Hint: Only one uart_init call needed to set baud rate [OK]
Common Mistakes:
  • Thinking multiple init calls are allowed
  • Assuming uart_init has no parameters
  • Ignoring case sensitivity in function names
5. You want to send the string "HELLO" over UART. Which code snippet correctly sends each character one by one?
hard
A. for(int i=0; i<5; i++) uart_send_char("HELLO"[i]);
B. for(int i=0; i<5; i++) uart_send_char('H' + i);
C. for(int i=0; i<5; i++) uart_send_char('HELLO'[i]);
D. for(int i=0; i<5; i++) uart_send_char("HELLO" + i);

Solution

  1. Step 1: Understand string indexing in C

    In C, single quotes ' ' denote characters, double quotes \" \" denote strings (char arrays).
  2. Step 2: Check each option for correct character access

    for(int i=0; i<5; i++) uart_send_char(\"HELLO\"[i]); correctly indexes the string literal to access each character 'H','E','L','L','O'.
  3. Final Answer:

    for(int i=0; i<5; i++) uart_send_char("HELLO"[i]); -> Option A
  4. Quick Check:

    Correct string indexing uses double quotes \"HELLO\"[i] [OK]
Hint: Use double quotes for string literal indexing in C [OK]
Common Mistakes:
  • Using single quotes for multi-character string literals
  • Adding integers to characters ('H' + i sends HIJKL)
  • Using pointer arithmetic without dereferencing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard