Skip to content

HardwareSerial calls the transmit interrupt one more time than needed. [imported] #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cmaglie opened this issue Nov 15, 2012 · 1 comment
Milestone

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 1008 moved from a Google Code project.
Added by 2012-08-17T23:16:20.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium, Component-Core

Original description

Each serial buffer transmission results in 1 extra interrupt to detect the TX
buffer being empty (verified with O-Scope).

Using USART3 as an example, here's an easy fix to remove this extra interrupt.

EXISTING:
ISR(USART3_UDRE_vect)
{
  if (tx_buffer3.head == tx_buffer3.tail) {
    // Buffer empty, so disable interrupts
    cbi(UCSR3B, UDRIE3);
  }
  else {
    // There is more data in the output buffer. Send the next byte
    unsigned char c = tx_buffer3.buffer[tx_buffer3.tail];
    tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE;

    UDR3 = c;
  }
}


NEW:
ISR(USART3_UDRE_vect)
{
  // There is more data in the output buffer. Send the next byte
  unsigned char c = tx_buffer3.buffer[tx_buffer3.tail];
  tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE;

  UDR3 = c;

  if (tx_buffer3.head == tx_buffer3.tail) {
    // Buffer empty, so disable interrupts
    cbi(UCSR3B, UDRIE3);
  }
}
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Apr 19, 2013
Before, the interrupt was disabled when it was triggered and it turned
out there was no data to send. However, the interrupt can be disabled
already when the last byte is written to the UART, since write() will
always re-enable the interrupt when it adds new data to the buffer.

Closes: arduino#1008
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 18, 2013
Before, the interrupt was disabled when it was triggered and it turned
out there was no data to send. However, the interrupt can be disabled
already when the last byte is written to the UART, since write() will
always re-enable the interrupt when it adds new data to the buffer.

Closes: arduino#1008
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue Jan 22, 2014
Before, the interrupt was disabled when it was triggered and it turned
out there was no data to send. However, the interrupt can be disabled
already when the last byte is written to the UART, since write() will
always re-enable the interrupt when it adds new data to the buffer.

Closes: arduino#1008
@cmaglie
Copy link
Member Author

cmaglie commented Jan 28, 2014

Fixed in 1.5.6

@cmaglie cmaglie closed this as completed Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant