ArduinoCore-sam icon indicating copy to clipboard operation
ArduinoCore-sam copied to clipboard

UARTClass::write function loses the first character when it is called many times in series.

Open vad7 opened this issue 7 years ago • 0 comments

Series like this:

Serial.print("r="); 
Serial.print(25); 
Serial.print(","); 
Serial.print(1); 
Serial.print(";");

Output: r=25,1;r=25,1;r=25,1;r=5,1;r=25,1;r=25,1;

Temporary fix (in UARTClass.cpp):

size_t UARTClass::write( const uint8_t uc_data )
{
    int nextWrite = (_tx_buffer->_iHead + 1);
    if(nextWrite >= SERIAL_BUFFER_SIZE) nextWrite = 0;
    while (_tx_buffer->_iTail == nextWrite)
      ; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent

    _tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
    _tx_buffer->_iHead = nextWrite;

    // Make sure TX interrupt is enabled
    _pUart->UART_IER = UART_IER_TXRDY;
   return 1;
}

vad7 avatar Jun 26 '18 10:06 vad7