Advice on Serial buffers (SERIAL2_RX_BUFFER_SIZE)

Status
Not open for further replies.

jensa

Well-known member
Hi all,
I'm working on project based on a Teensy 3.2 that talks to a Qt based application over Serial2. I kept running into problems with Serial data being corrupted, but after searching the forum for hours, I eventually found that when my main loop takes too long, it will prevent the buffer from filling. The first characters would always be correct, but after a certain amount of characters it got corrupted. Not always, but quite often.

I solved the problem by "packaging" the data sent from the Qt application and setting SERIAL2_RX_BUFFER_SIZE just a little above the packaging size. Now that I know what caused this, it makes sense that you'd miss some chars when your main loop can be busy for up to 90ms reading DAC's.

Looking at the code of "Serial2.c", it seems to support up to uint32_t as the SERIAL2_RX_BUFFER_SIZE. A larger buffer can be beneficial since this means fewer packages, but I would guess that large buffers has some drawbacks? If not - why are they 64 bytes by default?

So I'd love to hear advice for and against large/small buffers?
 
Hi Jensa,
like you I would like to know what caveats are attached to changing the Rx and Tx buffer sizes.
The one problem I can think of is more administrative in nature. Your changes to the core files will be over written every time you update Teensyduino, which is quite often. Will you remember in two years to update them after the update to the latest Teensyduino? I have put a special notice at the head of my program to remind me of this danger, pointing to the files and data that must be changed.
 
Status
Not open for further replies.
Back
Top