Maixduino icon indicating copy to clipboard operation
Maixduino copied to clipboard

Serial interface drops characters

Open technoblogy opened this issue 5 years ago • 2 comments

If you try to transfer more than about 960 characters from the Serial Monitor to the board via the serial interface it drops characters.

To demonstrate this run the following program that simply echoes characters to the Serial Monitor:

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Ready");
}

int count = 0;

void loop() {
  if (count % 64 == 0) {
    Serial.println();
    Serial.print(count);
    Serial.write(' ');
  }
  while (!Serial.available());
  Serial.write((int)Serial.read());
  count++;
}

Select and copy the following text:

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
  • Open the Arduino IDE Serial Monitor. Make sure it's set to Newline, 9600 baud.

  • Paste the text into the field at the top of the Serial Monitor and click Send.

The output looks like this; the red circles show the dropped characters.

Screen Shot 2020-03-04 at 17 09 56

Note: I'm running on a MacBook Pro using macOS High Sierra, with Arduino IDE 1.8.9, and Maixduino (k210) by Sipeed Boards Manager package 0.3.11.

technoblogy avatar Mar 04 '20 17:03 technoblogy

I think I've fixed it myself. In the following file:

Maixduino/hardware/k210/0.3.11/cores/arduino/RingBuffer.h

change:

#define RING_BUFFER_SIZE 64

to:

#define RING_BUFFER_SIZE 256

The value 256 seems to be the one used in other cores, such as Adafruit's samd core.

Please can this change be incorporated into future releases of the core.

technoblogy avatar Mar 05 '20 15:03 technoblogy

Actually I recommend a value of 1024.

technoblogy avatar Mar 16 '20 09:03 technoblogy