2025-09-08 11:17 PM - last edited on 2025-09-09 8:26 AM by Andrew Neil
Hi,
I am using USART4 in STM32L562E-DK eval board. with given configuration.
In which I am able to transmit the data correctly on TX based on which UART slave device is sending back the 4 bytes ACK and 16 bytes RESPONSE.
Using following code
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == UART4) // check correct UART
{
// Store received byte
//UART_Print("bytercv\r\n");
if (rxIndex < RX_BUFFER_SIZE_4)
{
rxBuffer4[rxIndex++] = rxData;
}
// Check if done
if (rxIndex >= rxTargetLen)
{
rxComplete = 1; // Mark reception complete
}
else
{
// Keep receiving next byte
HAL_UART_Receive_IT(&huart4, &rxData, 1);
}
}
}
I am able to receive the ACK but after some time when I read the RESPONSE there is not data available.
If I am reading only 4bytes of data what happens to remaining data is it loss?
Or I have to use FIFO based UART implementation.
Regards,
Aman
Edited to apply source code formatting - please see How to insert source code for future reference.
2025-09-09 6:27 AM
> If I am reading only 4bytes of data what happens to remaining data is it loss?
If you don't read out a byte before a new byte comes in, an overrun occurs and the new data will be lost. The peripheral will need to have the OVR flag cleared before it will receive new data.