cancel
Showing results for 
Search instead for 
Did you mean: 

Sending received data from PC (USB VCP) via UART in stm32

kmehranh
Associate II
Posted on November 19, 2016 at 23:38

I'm trying to send received data from PC (USB VCP) using UART. I generated the code with CubeMx for ''STM32f103c8t6'' and modified the ''CDC_Receive_FS'' function to send received data  by UART in interrupt mode. Data with size of few bits are sent correct but bigger data is corrupted. when I send below data,

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

receive,

1 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 20 21 22 23 24 2

I'm using ''Tera term'' and ''RealTerm'' for sending data. what should I do to fix it?!

Any help will be appreciated.

static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)

{

  /* USER CODE BEGIN 6 */

HAL_UART_Transmit_IT(&huart3,Buf,(uint16_t)* Len);

USBD_CDC_ReceivePacket(hUsbDevice_0);//Getting ready for receiving next data

  return (USBD_OK);

  /* USER CODE END 6 */ 

}

#!uart #!stm32f103 #stm32-usb-vcp
2 REPLIES 2
Posted on November 20, 2016 at 03:11

Not a HAL expert, but are you sure HAL_UART_Transmit_IT() doesn't block? You might be better buffering the data yourself and leaving immediately, and handling the USART stuff in another thread of execution, or within a USART callback.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kmehranh
Associate II
Posted on November 20, 2016 at 16:26

Thanks Clive,

Don't know if  ''HAL_UART_Transmit_IT()'' is blocking,  But Instead of that I used ''HAL_UART_Transmit()'' and it's working good.