STM32U585x UART Poll receive is happening only for first byte :
Dear Community
I have a problem with the UART1 on the STM32U585x board. I try to read some bytes in polling mode using HAL_UART_Receive();
And i set the size parameter to any number greater than 1 and i only receive 1 byte, even though i am sending more data from the other side.
This is really bizarre, i have used this function countless times in other projects with other controllers, and this is the first time this happens.
When i use the HAL_UART_Receive_IT(); It reads the whole message that can be 4,8 or 10 bytes.
I have an idea of what i am doing and i used the UART peripheral of the STM boards a lot and everything i tried didn't solved this.
Can someone please help me to figure out how to solve this? or is this some kind of a problem with the specific boards?
Thanks,
#define RX_BUFFER_SIZE 100
char rx_buffer[RX_BUFFER_SIZE] = "Hello_World\"r\n";
HAL_UART_Transmit(&huart1, (uint8_t*)rx_buffer, strlen(rx_buffer), HAL_MAX_DELAY);
rx_buffer[RX_BUFFER_SIZE] = 0;
char ch;
uint16_t index = 0;
// Receive 1 byte at a time until newline
if (HAL_UART_Receive(&huart1, (uint8_t*)&ch, 1, HAL_MAX_DELAY) == HAL_OK)
{
// Store character
if (index < RX_BUFFER_SIZE - 1)
{
rx_buffer[index++] = ch;
// If newline received, end string and echo back
if (ch == '\n')
{
rx_buffer[index] = '\0'; // Null-terminate string
// Echo the received string back
HAL_UART_Transmit(&huart1, (uint8_t*)rx_buffer, strlen(rx_buffer), HAL_MAX_DELAY);
// Reset index for next message
index = 0;
}
}
else
{
// Buffer overflow, reset
index = 0;
}
}
