Skip to main content
loic
Associate II
May 20, 2015
Question

USART Loopback with STM32F107

  • May 20, 2015
  • 13 replies
  • 2833 views
Posted on May 20, 2015 at 11:35

Hi,

I would make a loopback with my board STM3210C using USART2. I use the code

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Recieve%20more%20then%201%20Byte%20over%20USART&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=3862

. Here is my main code :

while(1)
{
//Wait until a byte is received
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
RXBUFF[j] = USART_ReceiveData(USART2);
if (USART_GetFlagStatus(USART2, USART_FLAG_TXE) != RESET)
USART_SendData(USART2, RXBUFF[j]);
j++;
if (j >= 1)
j = 0;
 } 

When I use the Hyperterminal to show the data exchange, I have a value returned only all the 4 or 5 values send. I just would send a number between 0 and 9, and receveid the same to verify the connexion. Thanks for your help Best regards Loïc
    This topic has been closed for replies.

    13 replies

    loic
    loicAuthor
    Associate II
    May 22, 2015
    Posted on May 22, 2015 at 13:53

    I started a

    new project from

    the VCP exemple here : http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743/LN1734/PF257882 --> STM32_USB-Host-Device_Lib_V2.1.0\Project\USB_Device_Examples\VCP. I just add this in the main function (file app.c) and obtain the same result in my hyperterminal as earlier...

    /* Main loop */
    while
    (1)
    {
    if
    (i++ == 0x100000)
    {

    uint16_t data;

    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    i = 0;

    while
    (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); 
    // Wait for Character

    data = USART_ReceiveData(USART2);

    while
    (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); 
    // Wait for Empty

    USART_SendData(USART2, data); 
    // Echo

    }
    }

    Tesla DeLorean
    Guru
    May 22, 2015
    Posted on May 22, 2015 at 14:50

    You can't do this

    USART_SendData(USART2, data); 
    // Echo
    USART_SendData(USART2, 
    'b'
    );

    The 'b' destroys the prior register content, you have to wait for TXE each time. I don't quite understand the point of the echo in the VCP example. Why wouldn't you do that in the IRQ handler? If you're interrupting on the RXNE signal, that would be the place to do this.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    loic
    loicAuthor
    Associate II
    May 27, 2015
    Posted on May 27, 2015 at 11:59

    I do this in the main function because I need to use ''data'' in order to make a Switch with it.

    Have you an idea why there is no good results in the HyperTerminal ? Problem of buffer size ?

    Thanks for your replies.