teensy 3.1 random line breaks in serial data output

Status
Not open for further replies.

zachtos

Well-known member
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?
 
Agreed, follow the Forum Rule!

This is the sort of thing which needs to be tested first without the radio. Or tested with Teensy's TX2 pin driving both the radio and a FTDI or similar USB-serial cable.

I'm confident testing will confirm Teensy is properly sending the entire string, but the radio is unable to always keep up at such fast baud rates, without flow control.
 
Thanks, code is very long/complex replicate without hardware, was looking for suggestions. I think we solved it and Paul was right, the radio needed some work on the receiving side.
 
Status
Not open for further replies.
Back
Top