dj0tt / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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);
  }
}

Original issue reported on code.google.com by blackwel...@gmail.com on 17 Aug 2012 at 11:16

GoogleCodeExporter commented 9 years ago
Sounds reasonable. Can you submit a patch that fixes this?

Original comment by dmel...@gmail.com on 28 Aug 2012 at 2:02

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 28 Aug 2012 at 2:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Attached. This should do the trick!

Thanks,
Nathan

Original comment by blackwel...@gmail.com on 28 Aug 2012 at 6:08

Attachments:

GoogleCodeExporter commented 9 years ago
Fix merged, will be released in 1.5.6.
Follow up here:

https://github.com/arduino/Arduino/issues/1008

Original comment by c.mag...@arduino.cc on 28 Jan 2014 at 5:05