0

I am working with an Arduino Due and I am having some issue with the serial Rx buffers size. I am using a GSM module and some of the replies to the Arduino exceed the number of bytes I can store in the buffer at once.

I have read about ways to increase the buffer size by modifying the Arduino default install files but I cannot take this route as my code may then be compiled on a machine with standard buffer sizes in the default install files and the module would not work correctly.

I am not sure if it is possible but I was hoping that someone might know how to increase the serial buffer size using the source code. If I can do it this way the buffer would always be the size I have specified.

  • Here are some good suggestions on this topic; groups.google.com/a/arduino.cc/forum/#!topic/developers/… – Mikael Patel Jan 19 '17 at 12:16
  • 3
    Just read from the serial port faster. Don't rely on the buffer for storing your data, read it from the buffer and store it yourself. – Majenko Jan 19 '17 at 13:06
  • @Mikael, thank you for the link I am reading through them now. – user1649972 Jan 19 '17 at 16:49
  • @Majenko My issue isn't with the speed that I read the serial at but more so with how often I can perform the reads. I am working on code written by someone else so I have limitations on how often I can read the data on the serial. One work around I am looking into is actually reducing my baud rate so that I will read that data slower and thus have more attempts to read and clear the bytes from the rx buffer before it has a change to fill. – user1649972 Jan 19 '17 at 16:53
  • Maybe hook into yield() to pull data into your own buffer then? – Majenko Jan 19 '17 at 16:57
1

Use timer interrupts to read and store the data from serial. Lets assume you are receiving data at baud rate of 115200 in default configuration (8data bits, 1 stop bit), 115200/9=12800 bytes per second, approximately 80 micro seconds for every byte, create a timer interrupt that is called once every 2 millisecond(Choose best time for your application making sure that receiver buffer does not overflow), In 2milli seconds 25bytes of data will be available in the buffer. So you can read data in batches of 25 each. From the interrupt read and store the available data from the buffer.

-3

I know this is for an input string, but allcocating a buffer size may help.

void setup()
{

  Serial.begin(57600);
  while(!Serial){;}
  inputString.reserve(20); //RESERVE SOME SPACE FOR INPUT STRING

  delay(50);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.