KurtE
Senior Member+
Maybe not too important, but was playing around with the Teensy 2 and I am playing with AX Buss code that runs at 1mbs.
I am running windows 10, 1.6.9...
Looking at output on Logic Analyzer I see there is gaps of time between bytes being output. Not sure if this shows it too well but:
So I took a look at: size_t HardwareSerial::write(uint8_t c)
in HardwareSerial.cpp and noticed the speed hack added to arduino in about 1.5.3 was not added here. The hack was when you call this function, if the queue is empty and the data register is empty, simply stuff it into the data register without adding it to queue and relying on interrupt handler. I found that this helped a lot at fast baud rates.
Code in current Arduino code base:
I am running windows 10, 1.6.9...
Looking at output on Logic Analyzer I see there is gaps of time between bytes being output. Not sure if this shows it too well but:
So I took a look at: size_t HardwareSerial::write(uint8_t c)
in HardwareSerial.cpp and noticed the speed hack added to arduino in about 1.5.3 was not added here. The hack was when you call this function, if the queue is empty and the data register is empty, simply stuff it into the data register without adding it to queue and relying on interrupt handler. I found that this helped a lot at fast baud rates.
Code in current Arduino code base:
Code:
size_t HardwareSerial::write(uint8_t c)
{
_written = true;
// If the buffer and the data register is empty, just write the byte
// to the data register and be done. This shortcut helps
// significantly improve the effective datarate at high (>
// 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
if (_tx_buffer_head == _tx_buffer_tail && bit_is_set(*_ucsra, UDRE0)) {
*_udr = c;
sbi(*_ucsra, TXC0);
return 1;
}
tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE;
...