0
\$\begingroup\$

According to the reference manual on UART for PIC here(page 7), the UxSTA register have two read-only bits; TRMT and UTXBF. While writing a simple transmission program over UART, I didn't notice any change if I include

while(UxSTAbits.TMRT != 1);

or

while(UxSTAbits.UTXBF);

before I send anything with the UxTXREG buffer. In what case is each of these bit relevant?

\$\endgroup\$
0
\$\begingroup\$

In block diagram at page 15, it is shown that the Transmit FIFO buffer is followed by Transmit Shift Register.

enter image description here

UxSTAbits.UTXBF bit indicates if the FIFO is full. If the FIFO is not full, you can write to UxTXREG register.

UxSTAbits.TMRT indicates if the last transmission has completed (FIFO and shift register are both empty). You should not turn off the UART or put MCU into sleep while the transmission is not completed. If you are not planning to do those, you can safely ignore the state of this bit.

\$\endgroup\$
  • \$\begingroup\$ @Asher Farooqui, The answer from user930473 is generally correct. There are some specific cases where an implementation can become problematic. For these cases you need to consult the errata for the specific device you are coding for. For example some parts when the application polls the UART status register rapidly it can provoke silicon bugs. \$\endgroup\$ – Dan1138 Mar 11 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.