Software serial : buffer size limit


I'm tryning to write a project to send SMS in PDU mode via a TC35 module I have to write and read to the module using softwareserial library

As i'm using PDU mode (mainly for concataning sms) i have to send string which are more than 255 length

The original buffer size was 64 i change it in softwareserial.h the line is now

define _SS_MAX_RX_BUFF 512

but when i try to read from software serial, the string are limited to 255 max size

Any idea how i could change this ?

In advance, thank you for helping


I think that you really, really want to be the one that figures this out. I’ll risk that some pedant will tell me that I’m not helpful, and say, “Here’s a clue:”

… the string[ s ] are limited to 255 max size

The buffer has space for more than 255 characters, but still you see only 255 of them. What kind of thing could cause that? What kind of objects does a number like 255 bring to mind?

Thank you for your answer
but, this is not a string problem

Let’s say i have set the GSM in PDU mode (AT+CMGF=0) and try to read message 8 (which is approx 350 length in PDU mode)

Here is a code :

#include <SoftwareSerial.h>   
 #define rxPin 10  
 #define txPin 9  

 // set up a new serial port for Leonardo  
 SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);  
 String message="";  //string we're sending  
 int i=1;
 void setup()  
 {//--For Leonardo  

   //empty the buffer
   while (mySerial.available()!=0)  Serial.print((char);
   Serial.println("Buffer empty");

 void loop()       

     //read buffer
     while (mySerial.available()!=0)

 ///this function is to send a sms message  
 void SendTextMessage()  



And here what is out

Buffer empty

It’s funny because i think i have the second part of the message only the first ime i send AT+CMGR=8 (size=93)
after i can only read 255 char

Thats not 255 it’s -1 the buffer is empty - read the docs.

By the way chars are not held in the buffer until you write the end of the message, theres no need to change the buffer size so put back as it was!


@tmd3: Nice thought, but the ring buffer head and tail pointers are "unsigned int"s

struct ring_buffer
  unsigned char buffer[SERIAL_BUFFER_SIZE];
  volatile unsigned int head;
  volatile unsigned int tail;

@holmes4 Thank you for answer, the buffer is not empty is i print it (Serial.print()) while reading i can see the first part of the answer (in my case, this is really the begining of the SMS in PDU mode)

If i change the buffer size back to 64 in softwareSerial.h it only show the first 63 char

So the change has effect, but i can't go over 255

May be the thought of string limitation is a good idea, i think there might be something in SoftwareSerial.h that limit the size of buffer to 255

Sorry @tmd3 , you were right - I was looking at the hardware serial code.

Yup, you need to sort out those buffer pointers around line 67-68 in SoftwareSerial.h.

@AWOL and @tmd3
Thank you so much you helped me solved my problem

I had to change line 42 in SoftwareSerial.h to

#define _SS_MAX_RX_BUFF 512

Also :
i changed line 67 and 68 in SoftwareSerial.h to

  static volatile uint16_t _receive_buffer_tail;
  static volatile uint16_t _receive_buffer_head;

and changed line 137 and 138 in SoftwareSerial.cpp to

volatile uint16_t SoftwareSerial::_receive_buffer_tail = 0;
volatile uint16_t SoftwareSerial::_receive_buffer_head = 0;

I had spent so many time to solve this… i can’t believe the solution isn’t easy to find on different forum or web pages; I think i’m not the first facing SMS in PDU mode with SoftwareSerial.


pasc: [ I ] can't believe the solution isn't easy to find ...

Maybe the next one who tries this will find the solution here. Do that one a favor, and read the sticky post at the top of this forum, entitled, "Read this before posting a programming question ..." In particular, read the part that says,

When you post your code put it between [ code ] ... [ /code ] tags. You can do that by hitting the # button above the posting area.

Then edit your posts to conform to that recommendation by putting code tags around the bits of code in your several posts. That will improve their readability and usefulness for posterity.