Skip to main content
michaelmccartyeng
Associate III
April 13, 2013
Question

usart hangs when nothing connected

  • April 13, 2013
  • 2 replies
  • 567 views
Posted on April 14, 2013 at 00:00

If I dont have anything on the usart port then it hangs when sending data. I have a ''debug'' usart output that I only want to use sometimes. But if I dont have anything connected then it will sit and hang here 

PUTCHAR_PROTOTYPE

{

  /* Place your implementation of fputc here */

  /* e.g. write a character to the USART */

  USART_SendData(Debug_USART, (uint8_t) ch);

  /* Loop until the end of transmission */

  while (USART_GetFlagStatus(Debug_USART, USART_FLAG_TC) == RESET)

  {}

  return ch;

}

which makes sense because its trying to send data but is never able to. 

Guess the best way around this is to have a switch to turn debug on or off, but it would be bad if a user hits that switch and then their unit never starts. 
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    April 13, 2013
    Posted on April 14, 2013 at 01:57

    Not sure what having nothing attached would change, unless you have hardware flow control enabled or something. Also why wait on TC? Back testing on TC is one of the least efficient ways of waiting for the USART, it would be better to front test on TXE.

    Some RS232 level converters have an INVALID signal that can be used to detect cable attachment.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    michaelmccartyeng
    Associate III
    April 19, 2013
    Posted on April 19, 2013 at 22:31

    Thanks Clive. 

    I had just copy pasted that out of some example somewhere without even thinking about it. Does that make me a script kiddie ? 

    Anyway I changed it and apart from being more efficient it does not hang there anymore. I think the TC flag was holding up something. Now I can disconnect it and it will still work no problem. 

    PUTCHAR_PROTOTYPE

    {

      /* Loop until the end of transmission */

      while (USART_GetFlagStatus(Debug_USART, USART_FLAG_TXE) == RESET)

      {}

        /* Place your implementation of fputc here */

      /* e.g. write a character to the USART */

      USART_SendData(Debug_USART, (uint8_t) ch);

      return ch;

    }