2016-11-19 02:38 PM
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 40receive,1 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 20 21 22 23 24 2I'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-vcp2016-11-19 06:11 PM
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.
2016-11-20 07:26 AM
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.