STM32 UART does not receive first byte
MCU: STM32L476RGT6
Hello,
I am using UART to read data from the NEO-M9N GPS receiver. My receive buffer stores all received data besides the first byte:


This forum states to add a delay between initializing UART and sending data, and this forum states to clear the buffer before transmitting data. However, neither solution works for me. These forums are addressing an issue where the first byte received is 0x00. However, my issue is that rather than receive 0x00, I skip the first byte entirely.
Any tips on how to fix this would be appreciated. Thanks.
static void MX_USART3_UART_Init(void);
UART_HandleTypeDef huart3;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
uint8_t buffer[100];
uint8_t buffer_idx;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART3_UART_Init();
buffer_idx=0;
while(HAL_TIMEOUT != HAL_UART_Receive(&huart3, buffer, 1, 10));
HAL_UART_Receive_IT(&huart3, buffer, 1);
HAL_Delay(1);
while (1) {
uint8_t arr[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x0E, 0x30};
HAL_UART_Transmit(&huart3, arr, sizeof(arr), HAL_MAX_DELAY);
HAL_Delay(100);
buffer_idx=0;
HAL_Delay(1000);
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart3, buffer+buffer_idx, 1);
buffer_idx++;
}
