2020-07-15 07:39 AM
Hello,
Am using STM32F407 (Discovery board). This is connected with a PC which is sending 100 bytes of data and realized that only 1 byte is received and remaining 99 bytes are lost. Below is the code excerpt running on STM32F407
while(1)
{
ret = HAL_UART_Receive(&huart6, &ins_data[i], 1,0);
if(ret != HAL_OK)
{
if(ret == HAL_TIMEOUT)
break;
Error_Handler();
}
rx_bytes++;
i++;
}
I do not want to use DMA but if data is available consume the data. No blocking, no waiting. I run the task at higher rate so as not to lose any byte in transmitted data from PC.
In above code say the transmitter has send 100 bytes, the value of i should get incremented by 100 bytes (for that matter the FIFO has been enabled. If at all FIFO length is an issue, at least till the size of FIFO it should not be an issue...). If the reason is that FIFO is not used unless we use DMA, I should at least get intermediate bytes but am getting the very first byte transmitted by PC everytime. Kindly guide...
2020-07-15 02:00 PM
> ret = HAL_UART_Receive(&huart6, &ins_data[i], 1,0);
This will only ever return 1 value.
> if(ret == HAL_TIMEOUT)
> break;
This is going to exit your while loop if no characters are available. If you want to wait for more characters, don't exit the loop on timeout. Considering handling the HAL_OK and HAL_TIMEOUT cases and going to Error_Handler on other codes.
break does not exit if statements, which was maybe your intention here.
ret = HAL_UART_Receive(&huart6, &ins_data[i], 1,0);
if (ret == HAL_OK) {
rx_bytes++;
i++;
} else if (ret != HAL_TIMEOUT) {
Error_Handler();
{