2013-04-13 03:00 PM
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.2013-04-13 04:57 PM
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.2013-04-19 01:31 PM
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;}