You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a problem with serial communication via the native port of an Arduino Due.
I'm using SAM core version: 1.6.12.
As discussed in https://forum.arduino.cc/index.php?topic=432148.0 a sketch halts completely once the SerialUSB write buffer is full. This is unacceptable for my use-case so I tried to prevent it using SerialUSB.availableForWrite() to check the fill level of the buffer and discarding the message.
This sketch runs fine until some connected device opens the serial port, reads a bit and closes it again. Then after a few seconds the sketch halts completely (led stops blinking).
The behaviour can be reproduced with this sketch:
unsignedlong timer_ser = 0;
unsignedlong timer_led = 0;
bool led_state = HIGH;
voidsetup()
{
pinMode(13, OUTPUT);
digitalWrite(13, led_state);
SerialUSB.begin(230400);
}
voidloop()
{
unsignedlong ms = millis();
// print every 50 msif (ms - timer_ser > 50)
{
timer_ser = ms;
// print only if there is enough space in the bufferif (SerialUSB.availableForWrite() > 80)
{
SerialUSB.print(ms);
SerialUSB.print("");
SerialUSB.print(SerialUSB.availableForWrite());
SerialUSB.println();
}
}
// toggle led every 500 msif (ms - timer_led > 500)
{
timer_led = ms;
led_state = !led_state;
digitalWrite(13, led_state);
}
}
Then, on your computer use minicom to read along for some time and close it. Alternatively you can run this python script (requires pyserial: pip3 install pyserial):
I've got a problem with serial communication via the native port of an Arduino Due.
I'm using SAM core version: 1.6.12.
As discussed in https://forum.arduino.cc/index.php?topic=432148.0 a sketch halts completely once the SerialUSB write buffer is full. This is unacceptable for my use-case so I tried to prevent it using
SerialUSB.availableForWrite()
to check the fill level of the buffer and discarding the message.This sketch runs fine until some connected device opens the serial port, reads a bit and closes it again. Then after a few seconds the sketch halts completely (led stops blinking).
The behaviour can be reproduced with this sketch:
Then, on your computer use minicom to read along for some time and close it. Alternatively you can run this python script (requires pyserial:
pip3 install pyserial
):Then wait a few seconds and the led will stop blinking.
In the forum thread I linked above modifications to libsam are discussed. Is this the way to go?
The text was updated successfully, but these errors were encountered: