Teensy 3.6 - changing Serial buffer size

Status
Not open for further replies.

Adrien T

New member
Hi,

I have found several posts on this forum, like this one : https://forum.pjrc.com/threads/38796-Teensy-3-6-Serial-Buffer about this topic; but none of the solutions provided appear to work for me, thus here I am.

I aim to receive 2k byte data every second from a sensor, and realize data fusion with other sensors, logging the aggregate in real time on a SD card.
I am afraid I'll miss some bytes cause the serial buffer will overflow when I'll stop listening for my Serial port for some time doing other calculations.

The default value for the Serial buffer size on RX is 64 bytes, as found in the serialx.c in the somearduinoversion\hardware\teensy\avr\cores\teensy3 folder.
It appears clearly with my following code.

Code:
void setup()
{  
  Serial.begin(9600);  
  Serial.println("Serial initialized");
  Serial2.begin(115200);
  Serial.println("Mirion initialized");

  Then I do some stuff with my SD card
}
void loop()
{
  int incomingByte;

  if(Serial2.available()>0) 
  {    
    incomingByte = Serial2.read();
    frameSize ++;
    
    // Detect frame completion
    if (incomingByte == startByte and prevByte == stopByte and prevprevByte != stopByte)
    {
        Serial.print("BOOM ");
        Serial.print("frame size :  ");
        Serial.println(frameSize);

        myFile.print("frame size :  ");
        myFile.println(frameSize);
        
        frameSize = 0;
    }
    
    // Writing on the SD card
    myFile.print(incomingByte, HEX);    
    myFile.print(' ');  
    
    prevprevByte = prevByte;
    prevByte = incomingByte;
  }
}

This code gives me this result :

mirion.png

The frame size is 2185 byte, and the first frame appears to have an extra 64 bytes, resulting of the buffer being emptied after filling during the setup part (?)

I tried the change the serial2.c in the core folder, while saving a copy of the original version in another folder. I tried various values both below and above the default 64 bytes value, and my code compiles (teensyduino) if the new core file, attesting the change by warning me the compilation options have been changed. Yet i can't see any difference in the results of my code, still this extra 64 bytes for the first frame received.

I feel I am clearly missing something but I can't figure out what !

Thanks in advance for any help,
 
Status
Not open for further replies.
Back
Top