Sytse Reitsma
New member
Hi,
I'm having some issues with sending data with 1ms interval over the Serial (USB) port. Every so often the buffer appears to overflow and takes significant time to recover.
The code below reproduces the issue:
It will happily send all the data until all of a sudden Serial.availableForWrite() suddenly plummets and will take a significant time to recover:
This pattern repeats:
I have some control over the interval by buffering the lines and batch sending them (the problem remains though), but I do not really understand why this is happening the way it does. You'd expect the availableForWrite to gradually decrease (with 2048 byte decrements when I look at the teensy code), not plummeting to 0 in 3 steps.
Sending less data per ms iteration (e.g. 90 bytes) also works, but I want/need to send more than that.
Is there any way to resolve this, or work around this?
Regards,
Sytse
I'm having some issues with sending data with 1ms interval over the Serial (USB) port. Every so often the buffer appears to overflow and takes significant time to recover.
The code below reproduces the issue:
C++:
uint32_t _prevTimeMs;
void setup() {
_prevTimeMs = 0;
}
void loop() {
auto nowMs = millis();
if (nowMs - _prevTimeMs >= 1)
{
_prevTimeMs = nowMs;
Serial.print(micros());
Serial.print(',');
Serial.print(Serial.availableForWrite());
Serial.print(',');
Serial.println("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec.");
Serial.send_now();
}
}
It will happily send all the data until all of a sudden Serial.availableForWrite() suddenly plummets and will take a significant time to recover:
Timestamp (us), availableForWrite, Lorem text
6846000,6144,Lorem ....
...
6898000,6144,Lorem ...
6899000,4096,Lorem ...
6900000,2048,Lorem ...
6901000,0,Lorem...
7024000,6144,Lorem...
This pattern repeats:
I have some control over the interval by buffering the lines and batch sending them (the problem remains though), but I do not really understand why this is happening the way it does. You'd expect the availableForWrite to gradually decrease (with 2048 byte decrements when I look at the teensy code), not plummeting to 0 in 3 steps.
Sending less data per ms iteration (e.g. 90 bytes) also works, but I want/need to send more than that.
Is there any way to resolve this, or work around this?
Regards,
Sytse