change the serial buffer size from within a sketch?

Hi,

as the title asks, is is possible to change the hardware serial buffer size from within a sketch or can it only be done by changing the values in the library?

I think you need to change the values in the library. If you change the size while the program is running there is a great risk that you will corrupt the memory for the whole project.

Why do you think it would be advantageous to change the value? If you use the technique in Serial Input Basics you can receive as much data as you wish without changing the buffer size.

…R

I use your methods, I am using your receiveWithStartandEndMarkers function with software serial (I know not good but no real choice), and have changed the values in the library as a temporary solution while I play with the code. Feel this is a bit of a hack and wanted to know if it was possible to change the values in the code

I have a sketch that receives up to 180 characters at a time and it choked around the 120/130 character mark. The sketch wasn't processing the data fast enough. I changed how I process the incoming data but still having issues. I now copy the incoming data to variables and process the data after getting the end of data flag. The sketch now chokes at around the 150/160 character mark. A littler better but not good. Have a few other things I want to try but wanted a way to get the sketch to work so I could finish other bits before going back and looking for a proper solution.

I've once had to reduce buffers as it wouldn't fit in the 512 bytes of RAM of the ATtiny85 :-) But that was for I2C. Really didn't need that big a buffer for 2-4 byte communication.

I think you can actually do it by adding your own #define with those values. You can't change the buffers on the fly (that'd be very hard to pull off as you start messing with memory management) but at compile time it should work.

MartynC: I have a sketch that receives up to 180 characters at a time and it choked around the 120/130 character mark. The sketch wasn't processing the data fast enough.

Then there's probably something wrong with your sketch, even at 921600 bps you have almost 11 µs (over 170 clock cycles) per character before the next comes in.

MartynC: The sketch now chokes at around the 150/160 character mark.

You have not posted your program so I cannot offer any solution.

...R

Robin2: You have not posted your program so I cannot offer any solution.

...R

Not yet in a position to ask the right questions. Still working on the code and have some things to try.

I was getting tired of manually changing the library so asked about changing the buffer size. Now using 2 versions of the IDEs. One with the original buffer size. One with a modified buffer size.

If you are interested. It is an update for www.dropcontroller.com Interestingly, the original was developed in IDE1.6.3 and I didn't have any issues. I am now using 1.8.5 and have problems.

This solution is a bit complex, but it's probably the only way to set the buffer size in the sketch code: http://forum.arduino.cc/index.php?topic=329709.msg2279367#msg2279367

MartynC: Not yet in a position to ask the right questions. Still working on the code and have some things to try.

You said in Reply #2 that you had a program that "chokes at around the 150/160 character mark". That is the program I want you to post.

...R