Skip to content

Commit

Permalink
Merge pull request #844 from ahshah/87_Serial_LINENIR_Usage_Fix
Browse files Browse the repository at this point in the history
Fix serial corruption on x7 chips
  • Loading branch information
SpenceKonde authored Sep 5, 2024
2 parents 2bb785e + 0ae2cad commit 7cdaa11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions avr/cores/tiny/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@
*_ucsrb |= _udrie;
#else
if(!(LINENIR & _BV(LENTXOK))){
//The buffer was previously empty, so enable TX Complete interrupt and load first byte.
LINENIR = _BV(LENTXOK) | _BV(LENRXOK);
// The buffer was previously empty, so load the first byte, then enable
// the TX Complete interrupt
unsigned char c = _tx_buffer->buffer[_tx_buffer->tail];
_tx_buffer->tail = (_tx_buffer->tail + 1) & (SERIAL_BUFFER_SIZE - 1);
LINDAT = c;
LINENIR = _BV(LENTXOK) | _BV(LENRXOK);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion avr/cores/tiny/Serial0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if(LINSIR & _BV(LTXOK)) {
//PINA |= _BV(PINA5); //debug
if (tx_buffer.head == tx_buffer.tail) {
// Buffer empty, so disable interrupts
// Buffer empty, so disable the Transmit Performed Interrupt
LINENIR = LENRXOK; //unset LENTXOK
} else {
// There is more data in the output buffer. Send the next byte
Expand Down

0 comments on commit 7cdaa11

Please sign in to comment.