2022-09-30 01:02 AM
Hello community,
I'm new to ST-MCUs, so maybe this question is very basic.
I'm developing an application for a customer board with a STM32L051R6TX.
For Communication we use USART1 und USART2, for logging I activated LPUART1.
On USART1 und USART2 I get telegrams every 50ms, 40byte long. Baudrate is 9600, 8N1.
To isolate my problen, I created a project with STM32CudeIDE with minimal C-Code.
Initially I activate the Receive Interrupt on both UARTS with 40 bytes, and the InterruptRoutine does this too as the very last command.
Then I added a UARTStateCheckFunction to read the StatusFlgas of the Uarts. It is called in the InterruptRoutine and in the mainCycle (there with 100ms delay).
The InterruptRoutine only counts its calls and the UARTStateCheckFunction also counts the calls, where was an error state on an USART.
I would expect, that the InterruptRoutine is called for every USART and for every telegram. But I receive only on one USART,
The other one gets Errors: RXNE:1 ORE:1 NE:0 FE:0 PE:0 TXE:1 BUSY:0 ABRE:0,
Resetting them in the UARTStateCheckFunction helps sometimes for the ORE Flag..
But on the next call of UARTStateCheckFunction ORE is true again.
Which of the USARTs receives and which errors is randomly.
I also tried to use polling both USART, but I get same behavior. On USART receives, the other one has ORE-Flag on and doesnt receive until timeout.
I also switched of all logging and string oprations on LPUART3 to save MCU time.The App is realy minimalistic.
Is it possible, that this MCU is to slow to process those telegrams on both UARTS?
(The real application has to do some things more in maincycle).
2022-10-07 01:07 AM
But I'm not shure, if I handle the ORE error really correct:
I get an ErrorInterrupt when ORE occures.
Then I look at uart->ErrorCode to check the type of the error.
If HAL_UART_ERROR_ORE is ON, then I do the two steps from the manual:
Read the ISR of the UART (there is no SR Register in HAL, as far as I can see)
(done with
__HAL_UART_GET_FLAG(uart, UART_FLAG_ORE)
which reads ISR)
Then I read one byte from DR
(done with
HAL_UART_Receive(uart,dummy,1,0)
which reads the RDR (=DR ?))
At last I call
__HAL_UART_CLEAR_OREFLAG(uart)
which clears the UART_CLEAR_OREF in ICR.
(Alternatively I could use
__HAL_UART_CLEAR_IT(uart, UART_CLEAR_OREF); //or
__HAL_UART_CLEAR_FLAG(uart, UART_CLEAR_OREF);
which does the same).
Is this a right approach?
2022-10-07 01:45 AM
But maybe I#m wrong and I mixed up some things.
Reading SR and DR is done in STM32F4 libraries,
Setting the UART_CLEAR_OREF Flag in ICR is done in STM32L0 libraries
to reset ORE-Error.
My MCU is a STM32l051R6T6.so
__HAL_UART_CLEAR_OREFLAG(uart);
Is enough eventually.