diff --git a/cores/arduino/SERCOM.cpp b/cores/arduino/SERCOM.cpp index 61e53a9c9..be7962ec2 100644 --- a/cores/arduino/SERCOM.cpp +++ b/cores/arduino/SERCOM.cpp @@ -152,6 +152,12 @@ bool SERCOM::isFrameErrorUART() return sercom->USART.STATUS.bit.FERR; } +void SERCOM::clearFrameErrorUART() +{ + // clear FERR bit writing 1 status bit + sercom->USART.STATUS.bit.FERR = 1; +} + bool SERCOM::isParityErrorUART() { //PERR : Parity Error diff --git a/cores/arduino/SERCOM.h b/cores/arduino/SERCOM.h index 4b1568b59..750592aee 100644 --- a/cores/arduino/SERCOM.h +++ b/cores/arduino/SERCOM.h @@ -158,6 +158,7 @@ class SERCOM bool availableDataUART( void ) ; bool isBufferOverflowErrorUART( void ) ; bool isFrameErrorUART( void ) ; + void clearFrameErrorUART( void ) ; bool isParityErrorUART( void ) ; bool isDataRegisterEmptyUART( void ) ; uint8_t readDataUART( void ) ; diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp index 7e8c027ac..dd797da4d 100644 --- a/cores/arduino/Uart.cpp +++ b/cores/arduino/Uart.cpp @@ -90,6 +90,13 @@ void Uart::flush() void Uart::IrqHandler() { + if (sercom->isFrameErrorUART()) { + // frame error, next byte is invalid so read and discard it + sercom->readDataUART(); + + sercom->clearFrameErrorUART(); + } + if (sercom->availableDataUART()) { rxBuffer.store_char(sercom->readDataUART()); @@ -114,7 +121,6 @@ void Uart::IrqHandler() if (sercom->isUARTError()) { sercom->acknowledgeUARTError(); // TODO: if (sercom->isBufferOverflowErrorUART()) .... - // TODO: if (sercom->isFrameErrorUART()) .... // TODO: if (sercom->isParityErrorUART()) .... sercom->clearStatusUART(); }