Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions avr/cores/MCUdude_corefiles/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class HardwareSerial : public Stream
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];

volatile int _rx_error;

public:
inline HardwareSerial(
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
Expand All @@ -131,6 +133,8 @@ class HardwareSerial : public Stream
inline size_t write(long n) { return write((uint8_t)n); }
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }
inline int rx_error(void) { return _rx_error; }
inline void clear_rx_error(void) { _rx_error = 0; }
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool() { return true; }

Expand Down
16 changes: 14 additions & 2 deletions avr/cores/MCUdude_corefiles/HardwareSerial_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ HardwareSerial::HardwareSerial(

void HardwareSerial::_rx_complete_irq(void)
{
if (bit_is_clear(*_ucsra, UPE0)) {
if (bit_is_clear(*_ucsra, UPE0) && bit_is_clear(*_ucsra, FE0) && bit_is_clear(*_ucsra, DOR0)) {
// No Parity error, read byte and store it in the buffer if there is
// room
unsigned char c = *_udr;
Expand All @@ -114,7 +114,19 @@ void HardwareSerial::_rx_complete_irq(void)
_rx_buffer[_rx_buffer_head] = c;
_rx_buffer_head = i;
}
} else {
}
else {
// Set that we had an error
if (bit_is_set(*_ucsra, UPE0)) {
_rx_error = -2;
}
else if (bit_is_set(*_ucsra, FE0)) {
_rx_error = -3;
}
else {
_rx_error = -4;
}

// Parity error, read byte but discard it
*_udr;
};
Expand Down