Skip to main content
Mohammad Rostamian
Associate III
March 7, 2018
Question

Why doesnt the Tc flag in usart clear?

  • March 7, 2018
  • 1 reply
  • 1887 views
Posted on March 07, 2018 at 22:25

Hi

I use stm32f407 to communicat with rs485.

I use DMA to transmit data. For controllig dirction pin, I check the USART_FLAG_TC. Whet it is set, I will push Dirction pin low and clear the 

USART_FLAG_TC by writing with 0. But it dosent clear. I must clear again. Other side, if using delay about 1us befor clearing that flag, it will be clear.

Does anybody have idea?

Best regards

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    March 7, 2018
    Posted on March 07, 2018 at 22:57

    I would not probe the state of the USART->SR in the debugger.

    It is not clear to me why you would need to explicitly clear it, when you see it is high change the direction control to input, and when you next go to output reverse the direction to output and write the USART->DR, this should immediately clear TC, and it will reassert when TXE=1 and the data transits the shift register on to the wire.

    In the time it takes you to eye-ball it in the debugger, the data has already cleared the wire.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Mohammad Rostamian
    Associate III
    March 8, 2018
    Posted on March 08, 2018 at 15:22

    I use this flag in pulling mode. To optimise my code, I check this flag, when this flag is set, then I clear this flag and push the driction pin low for waiting receiving new packet. If I dont clear this bit, I must push low the driction pin in every interval, that not necessary.

    Tesla DeLorean
    Guru
    March 8, 2018
    Posted on March 08, 2018 at 17:50

    Ok, but if that isn't working properly for you, consider alternatives where you carry state information, and don't rely on the flag in the same way.

    If you believe the hardware isn't behaving properly/appropriately you're going to need to decompose this into a very clear example/sample to provide to the validation groups.

    Consider abstracting ALL code that reads USART->SR to a SINGLE function, which also reflects the TC bit to a GPIO so you can monitor/review with a scope.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..