cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with USART_ReceiveData() and STM32F103 with Tera Term

leah
Associate
Posted on May 29, 2015 at 17:20

Hi,

I would like assistance in determining why I cannot properly use the USART_ReceiveData() function with my SMT32F103RE. I have been using Tera Term with a SparkFun FT232R usb to serial breakout board. Printing to Tera Term works fine, however, Our code can print from the board to Tera Term, but when we enter input from Tera Term using the USART_ReceiveData() function, it does not read the input. Perhaps I should be using another terminal emulator, or my code is off somehow. Here is the code:

 void InitDebug (void)

{

USART_InitTypeDef USART_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd (DBG_COM_GpIO_CLK, ENABLE);

RCC_APB1PeriphClockCmd (DBG_COM_USART_CLK, ENABLE);

// Configure DBG_COM_Tx as alternate function push-pull

GPIO_InitStructure.GPIO_Pin = DBG_COM_TX_GpIO_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init (DBG_COM_GpIO_PORT, &GPIO_InitStructure);

// Configure DBG_COM_Rx as input floating

GPIO_InitStructure.GPIO_Pin = DBG_COM_RX_GpIO_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init (DBG_COM_GpIO_PORT, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate = 115200;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No ;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_InitStructure.USART_HardwareFlowControl =  USART_HardwareFlowControl_None;

    

USART_Init (DBG_COM_USART_PORT, &USART_InitStructure);

        USART_Cmd (DBG_COM_USART_PORT, ENABLE);

}

static void getString(USART_TypeDef *com, char dataRecvd) {

    while(1)

    {

       while(USART_GetFlagStatus(com, USART_FLAG_RXNE) == RESET) {}

               debugPrintString(''PASSED\n'');

               dataRecvd = USART_ReceiveData(USART1_BASE);

       

       if (USART_GetFlagStatus(com, USART_FLAG_RXNE) != RESET)

              USART_SendData(USART2, dataRecvd);

          if (dataRecvd == 's')

                break;

    }

}

void debugScanString(char dataRecvd) {

       getString(USART1_BASE, dataRecvd);

}

Any help would be greatly appreciated! 

#stm32f103
1 REPLY 1
Posted on May 29, 2015 at 18:15

I've posted dozens of examples here. Not sure of any of your defines.

You should wait on TXE, and then send the data. Your if-not-rxne construct is almost guaranteed to drop the data every time.

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