We are using an ARM STM32L100RC. We receive in our firmware a message of just two characters through the USART 1. At 9600 kbps it works ok, at 19200 it fails sometimes, but at 38400 it fails one in ten times (approximately).
We receive the interrupt for the first character and we read it Then we receive the interrupt for the second character and we read it. But sometimes at 38400 we don't get the interrupt for the second character.
We use the typical
USART_INT_ST = USART1->SR;
if(USART_INT_ST & UART_FLAG_RXNE) /* Character received */
datorx = recibe232();
else if(USART_INT_ST & UART_FLAG_TC)
to know if we have received a character and to send a character.
We make this in USART1_IRQHandler.
After that we:
//Clear Tx interrupt
if ( __HAL_UART_GET_IT_SOURCE(&huart1, UART_IT_TC) )
//Clear Rx interrupt
if ( __HAL_UART_GET_IT_SOURCE(&huart1, UART_IT_RXNE) )
There are 8 HAL_NVIC_SetPriority( IRQn, 0, 0) in our source code. All of them are 0, 0. I have re-writed the source code to try with all of them at 15, 15 except HAL_NVIC_SetPriority(USART1_IRQn, 0, 0). But it is the same, the USART1_IRQHandler doesn't get any interrupt for the second character received from time to time.
I am analyzing the signals that the microcontroller receives and they are the same when it goes ok or wrong. I analyze the transition between the stop of the first character and the start of the second character and they are equal too.
I check with the software emulator that the diferent bits of the registers SR, CR1, CR2, CR3 remain with the values that they have to be. Comparing the ok and the wrong situation but they don't differ.
I try configuring 8 or 16 oversampling, ONEBIT equal to 0 or 1 but is the same.
What can be wrong? What can we try to get always the interrupt for the second character?