When does flag enable and disable in uart communication ?

Thread Starter

John99407

Joined Jul 12, 2019
77
I need to understand when the flag is enabled and disabled in stranded Uart Communication

1579955354318.png

As shown in figure I have three bytes of data, sending first byte, receiving second byte and again sending third byte via uart communication

As far as i understand uart flag check the condition before sending or receiving byte

What is the condition when Tx / Rx become enable ? What is the condition when Tx / Rx become disable ?
 

Papabravo

Joined Feb 24, 2006
21,225
It is enabled whenever the software decides it should be enabled. Usually, after initialization, the Rx and TX flags are enable ALL THE TIME.
 

JohnInTX

Joined Jun 26, 2012
4,787
I think TS is referring to the flags like TXIF that indicate when the UART is able to accept a character for transmission and RCIF that indicates when a character has been received. As noted, you ENABLE the UART one time during the initialization phase then you monitor TXIF and RCIF for each character you need to send or receive.

The diagram implies that TX and RX are on the same wire. In a UART, TX and RX are on separate wires and can happen at the same time.

There is a discussion of UART operation here:
https://forum.allaboutcircuits.com/threads/uart-function-flow.166369/post-1468324

@John99407 we have a lot of students from your school here on AAC. You should look through the threads to see how the others have worked on the subjects.
 
Last edited:

Thread Starter

John99407

Joined Jul 12, 2019
77
There is a discussion of those flags here:
I have read the entire discussion When TXIF is enable we can write the next byte to TXREG. When RXIF is enable we can read the next byte from RXREG. Uart can send the next byte until it sends the previous byte. TXIF flag is disabled until it sends the first byte. The TXIF flag is enabled again when the byte has been sent
 

JohnInTX

Joined Jun 26, 2012
4,787
I have read the entire discussion When TXIF is enable we can write the next byte to TXREG. When RXIF is enable we can read the next byte from RXREG. Uart can send the next byte until it sends the previous byte. TXIF flag is disabled until it sends the first byte. The TXIF flag is enabled again when the byte has been sent
Basically correct. Does that answer your question?
 

Thread Starter

John99407

Joined Jul 12, 2019
77
Basically correct. Does that answer your question?
Yes it's helpful But i have my own doubts Suppose What will happen if I typed 9 characters instead of 8 in the hyper terminal such as "123456789"

Will it receive only 8 characters such as "12345678" or "23456789" ?
 

JohnInTX

Joined Jun 26, 2012
4,787
Yes it's helpful But i have my own doubts Suppose What will happen if I typed 9 characters instead of 8 in the hyper terminal such as "123456789"

Will it receive only 8 characters such as "12345678" or "23456789" ?
It would receive all 9 characters. What makes you think otherwise?
 

JohnInTX

Joined Jun 26, 2012
4,787
I have read the entire discussion When TXIF is enable set we can write the next byte to TXREG. When RXIF is enable set we can read the next byte from RXREG. Uart can not send the next byte until it sends the previous byte. TXIF flag is disabled clear until it sends the first byte. The TXIF flag is enabled set again when the byte has been sent
Translation help: when referring to flags such as TXIF, it would be better to use the terms SET and CLEAR. A flag that is SET has a value of 1, CLEAR has a value of 0. ENABLE and DISABLE usually mean turning some function ON and OFF. For example, when you initialize the UART you ENABLE the transmitter by SETTING the TXEN flag to 1. Using standard terms makes your questions easier to understand and answer.
 
Last edited:

Thread Starter

John99407

Joined Jul 12, 2019
77
It would receive all 9 characters. What makes you think otherwise?
As such, 8-N-1 is the most common configuration for PC serial communications today. in which there is one start bit, eight (8) data bits, no (N) parity bits, and one (1) stop bits

According to this only 8 bit data will be send and received as I have shown in my previous post.

I think if I typed 9 characters instead of 8 in the hyper terminal such as "123456789"

I will it receive only 8 characters such as "12345678" And unless I type the next 8 bit data, the Microcontroller will not reschedule the data.

So now my first bit will be 9 If I type 123 after 9 then the microcontroller will not receive data because I do not have complete 8 bit data. I have only 9123

If I type this 912 0987, then microcontroller will receive because I have complete 8 bit sequence.
 

JohnInTX

Joined Jun 26, 2012
4,787
You are confusing bits and bytes.
Each character is 8 bits (1 byte). The character '1' is 00110001, the character '9' is 00111001, the character 'A' is 01000001 etc. The UART transmits and receives 8 bits per character, always.
 

Thread Starter

John99407

Joined Jul 12, 2019
77
You are confusing bits and bytes.
Each character is 8 bits (1 byte). The character '1' is 00110001, the character '9' is 00111001, the character 'A' is 01000001 etc. The UART transmits and receives 8 bits per character, always.
Sorry it's my mistake If the serial port has data of 9 bits 001110011 , the Uart will not receive 9 bits, it will only receive 8 bits (00111001) Is that possible ?

It's just logical question, I know it doesn't really happen
 

JohnInTX

Joined Jun 26, 2012
4,787
If the serial port has data of 9 bits 001110011 , the Uart will not receive 9 bits, it will only receive 8 bits (00111001) Is that possible ?
If the serial port is set up for 8 bits (9600,N,8,1) and it receives 9 bit data, it will be an error. It will also be an error if the UART is set up for 9 bits and only receives 8 bits. Note that the UART will always send and receive the number of bits it is configured for.
Note that you can configure the UART for 8 or 9 bit data but 8 bits is the most common. 9 bits would be used when you want to send a parity bit along with 8 bits of data. The PICs also use the 9th bit for other things but that is not common either.
In any case, the UARTs on both ends must be configured exactly the same - baud rate, number of bits, parity and number of stop bits - for communication to be successful.
 
Top