Electrical – How to check overrun

hal-librarystm32stm32f10xuart

I'm using an STM32F103C8T6 (aka blue pill) with Eclipse/System Workbench and HAL.

The following code:

 volatile HAL_StatusTypeDef result =
  HAL_UART_Transmit(&huart1, bytesToSend + currentSendIndex, 
  bytesPerMessageToSend, 100);

 volatile uint32_t error = HAL_UART_GetError(&huart1);

works fine when sending 1 byte, and (later) receiving 1 byte and iterating this.

However, when sending 3 bytes, I noticed, I only receive the first byte, and the next calls for HAL_UART_Receive result in a timeout.

This seems logical, because probably there is only 1 byte buffer in the UART.

However, what I don't understand, why does transmitting multiple bytes in the code mentioned, returns HAL_OK, and also the call to HAL_UART_GetError returns 0.

I assume an overrun has occurred for the 2nd and consecutive bytes… is this true, and if yes, how can I check this?

Best Answer

You can configure an interrupt to detect overrun errors. Actually a lot of interrupt are available to detect errors. From the reference manual:

enter image description here

Just for sure you could use the "Transmit data register empty" one as Tony has suggested.

As far as I know HAL IRQ handlers and IRQ calls for UART use all of these interrupts by default. The _IT versions of the UART calls enable all these interrupts.