Code:
String test "Sending one line of text"; //sample
test += "\r\n"; //add a carriage return and newline
Serial2.print(test); //send this every 100ms or so, many other interrupts and SD card audio etc playing in background
Results are this sometimes at high speed over bluetooth:
IN: Sending one line of text
IN: Sending one line of text
IN: Se
IN: nding one line of text
IN: S
IN: ending one line of text
IN: Sending one line of text
This has been a tough one to lookup on forums. I have a work around where I buffer the incoming data, but I'm curious why this happens sometimes where the lines break when they should not? I have tried converting String to byte array, and using Serial2.write(buffer, length), but no difference. Tried Serial2.flush() before and after a send, no difference, maybe made it worse actually. Also tried increasing buffer size in Serial2.cpp on teensy hardware folder. I am at 57600 baud, not much faster I can reliably go on bluetooth. I'm guessing my program has a lot going on with interrupts and timings, causing hiccups in serial output, but how to work around?
I also heard maybe learn to use DMA for serial output, no idea how to do that either though.
Anyone run into this before?