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?
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?