OA. free
Free
Texas Instruments Embedded Systems & Hardware Embedded Systems & Hardware Medium

3.

Texas Instruments technical mcq question, verified with a worked answer. Free to practise - no sign-up.

3. The UART communication protocol

You are using the following 8051 code to send a char using the UART communication protocol.

void UART_TxChar(char ch)
{
  SBUF = ch;
  while(TI == 0);
}

What is missing in the code?

Choose one option.
Show answer & explanation
Answer: A. A) The TI flag is not cleared

In the 8051 microcontroller, the Transmit Interrupt (TI) flag is set by hardware when a character has been transmitted. It is not automatically cleared by the hardware; the programmer must manually clear it to allow subsequent transmissions to be tracked.

Step-by-step Derivation:
Step 1: Analyze the provided code. The function UART_TxChar writes a character to the SBUF (Serial Buffer) register and waits for the TI flag to become 1, indicating the transmission is complete.
Step 2: Review the 8051 hardware specification for UART. The TI flag is set by the hardware when the 8-bit stop bit has been transmitted. However, the hardware does not reset this flag.
Step 3: Evaluate the loop while(TI == 0);. This loop correctly waits for the first character to be sent. However, once the loop exits, TI remains 1.
Step 4: Consider a second call to UART_TxChar. Because TI is still 1 from the previous call, the while(TI == 0); condition will be immediately false, and the function will return before the second character is actually transmitted, leading to data corruption or loss.
Step 5: Conclusion: The statement TI = 0; must be added after the while loop to reset the flag for the next transmission.