AnsweredAssumed Answered

USART2 Only Receives While Stepping in Debugger

Question asked by roofie01 on May 6, 2016
Latest reply on May 6, 2016 by roofie01

Set up on USART2 on STM32F4 Discovery board. Using PA2, PA3.
I'm using Teraterm with a USB to serial adapter at 115200.
After configuration, I send a string from the STM32F4 ("Hello\r") which I see on the terminal window. As below...


UART_PutStr("Hello\r")  //this appears in Teraterm window

while (1)
        // Get a char from PC
         uint16_t data = USART_GetChar();
         if( data == 'Q")
       //never gets here....after hitting Q on keyboard. except when stepping (see below)

And this is the get char function....

int16_t USART_GetChar(void)
    while (  !(USART2->SR & USART_FLAG_RXNE)  );    
    return USART_ReceiveData(USART2);         

If I just let the code run, and enter Q on the keyboard, it never sees it - it's not "getting the char".  However, if I put a breakpoint on this line:

while (  !(USART2->SR & USART_FLAG_RXNE)  );  

the debugger stops there. I then enter a Q into Teraterm, then step the debugger, and then it seems to receive and return the character.
I've tried a delay loop of microseconds to milliseconds in the while loop and it makes no difference.

Instead of "printf", I've also tried enabling one of the Discovery LED's and just running the app without the debugger. Makes no difference.

What gives here? Did I miss something obvious? 

Thanks for any suggestions....