Serial buffer size increase Teensy 3.2

Status
Not open for further replies.

George1

Active member
Hi,

I am using the Arduino 1.8.3 and Teensyduino 1.37 and I am trying to increase the serial buffer size by modifying serial1.c to serial6.c files (located in C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3). The original buffer sizes were set at 64 and 40 bytes and I increased that to 128 and that worked pretty well. Then I needed to increase the size to 250 but that did not work. It still seems to limit the RX buffer to around 128 bytes.

Any ideas of advice on what might be going on?

Thanks,
George
 
My serial1.c tx and rx serial buffers are both 512 bytes, and I don't have any problems. Not sure about serial6?
 
Hi,

I originally changed the RX and TX buffers to 128 and that worked well and then when I changed the number to 255 it seem to still hold only about 128 bytes in the RX buffer. I tried 512 as you suggested but still seems to hold only about 1228 bytes in the RX buffer.

Thanks
 
Hmm... I send 260 bytes of data from one teensy 3.2 to another to transmit audio data on serial1 for real time audio transfer.

I can't be much more help unless you post code.
 
Hi,

I was able to write a simpler program that replicates the serial buffer issue I am trying to resolve. I am communicating between two Teensys 3.2. First Teensy is sending long serial string once per second on Serial port 1 (sting is updated every time). The second is trying to read the data string via Serial port 3. The second Teensy program has an intentional time delay that simulates Teensy dealing with other issues until it is ready to read from the buffer.

//Send Data Teensy 1
#include <MsTimer2.h>
int i =0;

void setup() {
Serial1.begin(460800);
MsTimer2::set(1000, data); // 500ms period
MsTimer2::start();

}

void loop() {

delay(900);
}

void data() {

i++;

for( int k = 0 ; k < 20 ; k++){
Serial1.print(1000+i*i+k*k);
Serial1.print(",");
}

Serial1.print("T");

}






//Receive Data Teensy 2
char Terminator = 84; //ascii T
String SaltDataIn = "";

int time1 =0;

void setup() {
// put your setup code here, to run once:
Serial.begin(460800);
Serial3.begin(460800);

}

void loop() {
// put your main code here, to run repeatedly:

delay(800);

if (Serial3.available() > 0) {
SaltDataIn = Serial3.readStringUntil(Terminator);
}

Serial.println(SaltDataIn);

while( (millis() - time1) < 1000){

}

time1 = millis();

}
 
I forgot to state. The code works just fine until the receive buffer over flows at 120 bytes despite 256 bytes setting in the serial3.c file.

Here are few lines copied form the serial monitor:

9281,9282,9285,9290,9297,9306,9317,9330,9345,9362,9381,9402,9425,9450,9477,9506,9537,9570,9605,9642,
9464,9465,9468,9473,9480,9489,9500,9513,9528,9545,9564,9585,9608,9633,9660,9689,9720,9753,9788,9825,
9649,9650,9653,9658,9665,9674,9685,9698,9713,9730,9749,9770,9793,9818,9845,9874,9905,9938,9973,10010,
9836,9837,9840,9845,9852,9861,9872,9885,9900,9917,9936,9957,9980,10005,10032,10061,10092,10125,10160,10197,

Thanks
 
Maybe it is due to using readStringUntil, as you see the method definition: String readStringUntil(char terminator, size_t max = 120);

So it has a default size max of 120... You might try passing 256 as second parameter.
 
Thanks a lot Kurt. Your advice fixed the problem I was having completely.

It was an old code I was updating and it worked fine before so that function might have been updated in the mean time to include max string lenght.

Thanks,
George
 
Hello josechow,

maybe you can help me with my project.
I have a teensy 3.2 and i need to write a GPS-String ( it may can have more then 64 bytes, ~68 bytes) as a slave_writer to a Master_receiver. But if I write the GPS string with Wire.Write(gps_string.c_str()); it only sends the 32 bytes :)
And you said you are sending 260 bytes with one request. How i can do that in my project ?

If the buffer is hardware limited to 32 bytes i have to split the GPS string in 2 or 3 datapackages with 32byte. I need to split the string in the loop() right ? If i do that in the ISR (requestEvent) it could be a problem ?
And i think i need to check if the Tx Buffer is empty after the each datapackage which i want to send, before i send the next package via i2c ?

Many thanks in advance...
 
DaKe looks like you are using Wire library? If so you can probably fix this, by
Editing the Wire library: In my case I have Teensyduino installed on my D drive, so the Wire library is stored at:
D:\arduino-1.8.3\hardware\teensy\avr\libraries\Wire

If you edit the WireKinetis.h (Again I am assuming T3.x or T-LC and not T2...)
You will see a line in my case on line 35: #define BUFFER_LENGTH 32

Note: Probably too generic of a global define... But try changing the 32 to something bigger and rebuild your program
 
Hello Kurt,

thank you very much. It solved my problem... I was thinking about functions to split the string, because I thought its limited by Hardware. But to change the Buffer_Length is much easier ofc ;)

Thanks
 
Is there a limit? yes ;)

....

Obviously it needs to be smaller than your size of memory, but a quick look at the code it looks like it is using an index variable of type uint8_t, so that would probably imply it needs to be < 256
 
So now i changed the Buffer_Length to 512 and send the string:String test_string_6xgps = "$GPRMC,141615.114,V,4154.931,N,07402.497,W,73.2,3.93,100817,,E*45 $GPGSA,A,2,19,16,05,02,01,04,,,,,,,0.4,0.3,0.8*31 $GPGSV,2,1,06,19,56,047,49,16,12,331,28,05,82,229,61,02,21,328,86*71 $GPGSV,2,2,06,01,22,217,84,04,36,200,46*77 $GPGSV,2,1,06,19,06,349,42,16,51,079,66,05,60,026,23,02,16,085,15*7D $GPGSV,2,2,06,01,29,024,62,04,52,123,47*77";
with...

void requestEvent (void) { //
Wire.write(test_string_6xgps.c_str());
}
But if i check the i2c communication with a oscilloscope there are only 80 Bytes instead of all ~250 Bytes. The count of 80 is wired... if there would be 128 its clear but why 80 ?

Thanks in advance...
 
didnt saw your edit before i write the last edit :)
So now i changed the BUFFER_LENGTH to 128 and now it puts the first 128 Bytes on i2c-bus... so now its clear.
So i think if i want to put a longer string on the bus for each master request, i have to do it like this:
(I want to send 6 gps strings...)

void requestEvent (void) { //
Wire.write(test_string_rmc.c_str()); // gps string
while(!Wire.done())
Wire.write(test_string_gsa.c_str()); // gps string
while(!Wire.done())
Wire.write(test_string_gsv1.c_str()); // gps string
while(!Wire.done())
Wire.write(test_string_gsv2.c_str()); // gps string
while(!Wire.done())
Wire.write(test_string_gsv3.c_str()); // gps string
while(!Wire.done())
Wire.write(test_string_gsv4.c_str()); // gps string
}
But i think its not the best realization because they requestEvent should be a short as possible, right ?

that is the description of wire.done():
Wire.done(); - returns simple complete/not-complete value to indicate I2C status
return: 1=Tx/Rx complete (with or without errors), 0=still running

thanks in advance and maybe you have some other idea for my problem, that would be awesome ;)

DaKe
 
Status
Not open for further replies.
Back
Top