Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Teensy 3.6 - changing Serial buffer size

  1. #1
    Junior Member
    Join Date
    Jul 2018
    Posts
    1

    Teensy 3.6 - changing Serial buffer size

    Hi,

    I have found several posts on this forum, like this one : https://forum.pjrc.com/threads/38796...-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\teens y3 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 :

    Click image for larger version. 

Name:	mirion.png 
Views:	10 
Size:	4.9 KB 
ID:	14144

    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,

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,153
    Quote Originally Posted by Adrien T View Post
    Yet i can't see any difference in the results of my code
    Arduino prints a memory usage summary. Look for those numbers to change when the buffer is using more RAM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •