2025-06-23 11:07 PM - edited 2025-06-24 4:57 AM
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;
}
}
2025-06-25 12:50 AM - edited 2025-06-25 12:53 AM
@ram_jana wrote:Can I use the polling method to receive responses from the Iridium 9603N modem, as per its design? Will polling supports to receive response from modem as per this design ?
As @TDK and @Tesla DeLorean have explained, the trouble with polling is that the receiver has to be ready and waiting before the transmitter starts sending.
That can be very difficult to achieve with a 3rd-party device over which you have little control.
With a modem, you'd have to ensure that it can never send anything unsolicited.
ie, it never sends anything except in response to a command/request.
If you can do that, you know that the only time it will send is in response to a command/request - so you can be ready.
But it means that your receiver will need to block while it waits for the response to start, and then wait for it to complete.
Which can make the rest of your application hard to manage.
This is why using interrupt-driven reception is generally preferred.