diff --git a/ports/stm32f10x/rs485.c b/ports/stm32f10x/rs485.c index 91d8148f..99064921 100644 --- a/ports/stm32f10x/rs485.c +++ b/ports/stm32f10x/rs485.c @@ -110,17 +110,9 @@ bool rs485_receive_error(void) return false; } -/*********************************************************************/ /** - * @brief - *USARTx - *interrupt - *handler - *sub-routine - * @param[in] - *None - * @return - *None - **********************************************************************/ +/** + * @brief USARTx interrupt handler sub-routine + */ void USART2_IRQHandler(void) { uint8_t data_byte; @@ -130,6 +122,12 @@ void USART2_IRQHandler(void) data_byte = USART_ReceiveData(USART2); (void)FIFO_Put(&Receive_Buffer, data_byte); } + if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) != RESET) { + /* note: enabling RXNE interrupt also enables the ORE interrupt! */ + /* dummy read to clear error state */ + data_byte = USART_ReceiveData(USART2); + USART_ClearFlag(USART2, USART_FLAG_ORE); + } } /************************************************************************* diff --git a/ports/stm32f4xx/rs485.c b/ports/stm32f4xx/rs485.c index 41aa36b5..6c8fe62d 100644 --- a/ports/stm32f4xx/rs485.c +++ b/ports/stm32f4xx/rs485.c @@ -149,6 +149,9 @@ void USART6_IRQHandler(void) } /* check for errors and clear them */ if (USART_GetFlagStatus(USART6, USART_FLAG_ORE) == SET) { + /* note: enabling RXNE interrupt also enables the ORE interrupt! */ + /* dummy read to clear error state */ + data_byte = USART_ReceiveData(USART6); USART_ClearFlag(USART6, USART_FLAG_ORE); } if (USART_GetFlagStatus(USART6, USART_FLAG_NE) == SET) {