2016-04-28 06:20 AM
Dear all,
I have problem transferring relatively large block data (>= 600 bytes) over USART. All blocks smaller than 600 bytes can be sent successfully from MCU and the host at the other end receives that correctly. I have the following routine with some timeout to send the data from MCU to the host: static void send_response(uint8_t *response, uint16_t frame_length) { for (int i = 0; i < frame_length; ++i) { USART_SendData(UART4, response[i]); timer.Start(TIMEOUT); while ((!timer.iselapsed()) && (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET)); } } The logic seems to be pretty simple but it doesn't work for large frames and it seems that the USART_FLAG_TC is never set so the communication will not be successful. The limit of 600 bytes seems to be very low so I am almost sure that I am doing something wrong. Any help is highly appreciated. Regards, Dan2016-04-28 06:29 AM
I'd front check TXE, back checking TC is the slowest possible method.
Does it work without your time out method if you check TXE before sending each byte? It it only fails with your time out, then review the math there.The USART may also break if you park a debug view over the peripheral.2016-04-28 08:40 AM
Thank you very much clive1. I changed the check to front TXE and got some speedup. The problem is solved now and it happened because I had forgotten to kick the watchdog in the sending loop. This bug didn't show up before because the data that I used to send/received was small, but when the data is large, the watchdog needs to be kicked.
Thanks again, Dan