2015-05-20 02:35 AM
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¤tviews=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
2015-05-22 12:02 AM
Thank you for the time you give to my problem.
I have tried your code, there is no problems with the serial port, but when I use the VCP configuration with this code, It's impossible to send data (Putty etablishes the connexion, but it shows nothing when I type on the keyboard). The problem comes from USART_Cmd(), so I have commented it and came back at the same point than yesterday. EDIT : I have made a simple test and I obtain this result in Putty : 1234abab 12345abab 123456abab 123ababab. All the numbers are typed by me.while
(1)
{
uint16_t data;
while
(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
// Wait for Character
data = USART_ReceiveData(USART2);
USART_SendData(USART2,
'a'
);
Tempo(1000);
while
(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
// Wait for Empty
USART_SendData(USART2, data);
// Echo
USART_SendData(USART2,
'b'
);
Tempo(1000);
}
2015-05-22 04:53 AM
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
}
}
2015-05-22 05:50 AM
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.
2015-05-27 02:59 AM
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.