Go Down

Topic: 64-byte serial receive buffer (Read 657 times) previous topic - next topic

nantais


AFAIK it's just a matter of changing the SERIAL_BUFFER_SIZE #define in HardwareSerial.cpp, however the same value is used for both Tx and Rx so you waste a lot of RAM if your comms is one-sided.

This should really be a parameter or another Serial method call IMO.

______
Rob

That makes a lot of sense.  There are two issues that I know of.  The first is that 1.5 doesn't appear to be using a Tx buffer from what I see in the sourcecode.  I might be wrong about that, but at first read it appears to be the case.  The single-byte write() method has a spin lock until the TXRDY status bit is set.  We're working around that by testing TXRDY ourselves in the main loop() and only calling write() when we know the bit is set.  The second issue is that we would need to make sure the variables in the ring buffer are being updated atomically if they're going to be holding values bigger than 255.  That's probably true for the Due, but we would need to be sure.

Tom

Graynomad

#6
Jul 16, 2013, 05:55 pm Last Edit: Jul 16, 2013, 05:57 pm by Graynomad Reason: 1
Quote
The second issue is that we would need to make sure the variables in the ring buffer are being updated atomically

Doesn't look like it.

Code: [Select]
int HardwareSerial::read(void)
{
  // if the head isn't ahead of the tail, we don't have any characters
  if (_rx_buffer->head == _rx_buffer->tail) {
    return -1;
  } else {
    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
    return c;
  }
}


The Due would be the same I assume.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up