Skip to main content
haye
Associate III
May 7, 2020
Question

STM32F2 RXNE flag FROM SR register clear without reason

  • May 7, 2020
  • 6 replies
  • 4948 views

Hello,

I am using UART4 from a STM32F2. I am sending a data then my RXNE FLAG from SR register go from 0 to 1. Without doing anything (no read of the DR register and no clearing manually the flag) it go back to 0 after some time. So I am missing the data in my IT routine.

I can't figure out why this happening. Could someone have an idea of what the issue could be ?

This topic has been closed for replies.

6 replies

berendi
Principal
May 7, 2020

Do you watch the data register in the debugger? Unfortunately the UART peripheral has no way of knowing whether it was read by the program running on the MCU or by the debugger, and resets the flags in both cases.

What does the SR register contain, are there any other flags set?

haye
hayeAuthor
Associate III
May 7, 2020

Thank you for your answer. Yes I am checking the DR content and he is still with my data in but the flag still go to 0.

TDK
May 7, 2020

> Does checking the content of the adres is equivalent to read it ?

Yes. Reading the register in any manner will reset the flag.

"If you feel a post has answered your question, please click ""Accept as Solution""."
haye
hayeAuthor
Associate III
May 7, 2020

Ok so if I not read it how could I know if the debugguer is doing it ? Because my original problem is in my application I am sending and receiving data and it's working well but from time to time I am missing the last byte and I think is due to this flag reset. But I can't figure why this could happen. I've test to just check the SR flag. Not doing action on DR and got same results

TDK
May 7, 2020

> Ok so if I not read it how could I know if the debugguer is doing it ?

The debugger only does what you ask it to do. Don't set watchpoints at this register. Don't view peripheral addresses.

Attach a logic analyzer on the traces and see what it's actually doing. Unlikely that the SR flag is not behaving properly. Check for UART error flags. Might be a timing issue.

"If you feel a post has answered your question, please click ""Accept as Solution""."
haye
hayeAuthor
Associate III
May 7, 2020

Ok thanks this is what i've done in the second part no action to the DR register with the debugguer and none with my code also. And still this reset. The issue is I am using old IDE and don't get tracer for this one.Question is this problem could happenned with a bad configuration of the peripheral ? or any other reason ?

waclawek.jan
Super User
May 7, 2020

> I am using UART4 from a STM32F2. I am sending a data then my RXNE FLAG from SR register go from 0 to 1.

RXNE should be set when you *receive* data, not when *sending* it from the STM32 USART.

> Without doing anything (no read of the DR register and no clearing manually the flag) it go back to 0 after some time.

How do you know?

JW

haye
hayeAuthor
Associate III
May 7, 2020

>RXNE should be set when you *receive* data, not when *sending* it from the STM32 USART.

Yeah sure. I am sending a data then the flag is set when I received it.

> How do you know?

Knowing that I'm doing nothing on DR ? or knowing that the flag is going to 0 ? for the second case I am knowing it by checking the SR register

waclawek.jan
Super User
May 7, 2020

>>RXNE should be set when you *receive* data, not when *sending* it from the STM32 USART.

> Yeah sure. I am sending a data then the flag is set when I received it.

So you have some loopback enabled?

> for the second case I am knowing it by checking the SR register

Okay so post a minimal but complete compilable code exhibiting the problem.

JW

haye
hayeAuthor
Associate III
May 7, 2020

>So you have some loopback enabled?

Yes hardware one my TX is going on my RX pins

> Okay so post a minimal but complete compilable code exhibiting the problem.

Ok I will clean the code to send you the minimal one I used (The application is huge and old) I will clear all the thing I comment and send it.

Thanks for your help !

waclawek.jan
Super User
May 20, 2020

And, in the debugger, when the breakpoint is hit, you watch the USART registers?

JW

haye
hayeAuthor
Associate III
May 22, 2020

I am watching the 2 pointer :

  1. FLAG_IT_UART4 = 0x40004C00;
  2. FLAG_IT_EN_UART4 = 0x40004C0C;

First for the SR register

Second for CR1 to be sure everything is well activated