cancel
Showing results for 
Search instead for 
Did you mean: 

Some questions about USART operationi

parisa
Senior
Posted on March 09, 2017 at 08:34

Hi,

I want to know more about USART operation and I will appreciate for your comment and explanations.

1)If RXNE=1 and it execute interrupt subroutine always it means that we a valid data? even the between operation something occurs and or we have a connection lost?

2)what does Noise flag exactly do?(In the 3-bit sampling if one of samples fails  we should ignore the received data)?

3)In receiving mode if something happens that one of error flag is set(for example I lost my connection during receiving(I remove Rx line) )  and after that the next character is sent (Or I connect the RX wire  again)what does the MCU work? it receives the next character or do something else?

4)if I don't read the one of received bytes and overrun error occurs (even the interrupt flag of RXNE has been activated), what is the reaction of MCU?

3 REPLIES 3
S.Ma
Principal
Posted on March 09, 2017 at 17:43

Looking at the reference manual, USART description (50 pages). It looks like once a start bit is detected the bit sampling goes on until the byte is transferred. Then RXNE will be set and interrupt will be used to check if there was errors during sampling. 

1) When RXNE is set and analysed in interrupt, you need to check the error flags to confirm the DR content.

2) Data should be considered corrupted.

3) When USART is enabled, it seems to run continuously

4) This is OVERRUN case (received more bytes than read)

For plug/unplug, it will create glitches. You might reduce them by configuring RX as input with pull-up.

If the link is poor quality use the parity bit... that is its purpose.

Another newer method is to compute a data block CRC (checksum) to make sure the transmission is good. The size of the CRC depends on the BERR (bit error rate). Many books about this including corrupted bit method such as Vitterbi...

Posted on March 09, 2017 at 17:48

You should qualify RXNE in the interrupt handler prior to reading DR. Don't read DR in multiple places in your foreground code if you are using an IRQ, you'll create race conditions, as will viewing the register content with a debugger.

You will need to clear framing or parity error by reading DR also, don't assume RXNE will flag in these conditions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
parisa
Senior
Posted on March 10, 2017 at 11:34

Thanks for your contribution and response.

Yes, I would prefer to use RXNE interrupt. I want to know

1) in ISR , if I use USART_ReceiveData from SPL can In variable overflow ? because USART_ReceiveData function return a two byte variable;

char In;

In=USART_ReceiveData(USART1);

2) for a secure system(Only RXNE interrupt has been set), it's a good approach that when RXNE occurs, first I check Noise and frame error and then read DR (USART input register)(That can erase error flags) and after that according to Noise and frame error I decide that input data is valid or not? , Isn't it?