Serial buffer

Post here first, or if you can't find a relevant section!
krishna
Posts: 7
Joined: Tue Apr 26, 2016 6:15 am
Location: Hyderabad,India

Serial buffer

Postby krishna » Tue May 03, 2016 2:52 pm

Hi,
I am working with maple mini,
when am trying to read data from Serial.read() function am unable to read more then 64 byte.
How to increase the size of the Rxbuffer?

for example

void setup()
{
Serial.begin(9600);
Serial2.begin(9600);
}

void loop()
{
delay(1000);
if(Serial2.available())
{
Serial.print("Number of bytes to read : ");
Serial.println(Serial2.available(),DEC);
whlile(Serial2.available())
{
Serial.read();
}
}
}



Every time "Number of bytes to read : 63 " even i have more data in receiver.
Please tell me how to increase the buffer size ?
or any other idea to get more data through the "Serial.read()" ?

Thank you very much
Krishna.

User avatar
GrumpyOldPizza
Posts: 166
Joined: Fri Apr 15, 2016 4:15 pm
Location: Denver, CO

Re: Serial buffer

Postby GrumpyOldPizza » Tue May 03, 2016 3:08 pm

You could edit cores/maple/HardwareSerial.h and set SERIAL_RX_BUFFER_SIZE to say 128 ...

The 63 is due to the buffering scheme that requires one entry to be not occupied. A 64 byte buffer will always max out at 63, a 128 byte buffer at 127 and so on.

You also don't have more than 63 bytes in the receiver. The extra data that cannot be buffered is simply discarded.

Anyway mind quickly explaining why 63 bytes of receive buffer is not sufficient for your scenario ?

- Thomas

User avatar
mrburnette
Posts: 1769
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Serial buffer

Postby mrburnette » Tue May 03, 2016 5:00 pm

GrumpyOldPizza wrote:You could edit cores/maple/HardwareSerial.h and set SERIAL_RX_BUFFER_SIZE to say 128 ...



Absolutely not recommended. Unless one knows (really, really knows) what one is doing, the core is off-limits.

Welcome @Krishna :!:

Now, to the problem, which is more apparent when properly formatted:

Code: Select all

void setup()
{
  Serial.begin(9600);
  Serial2.begin(9600);
}

void loop()
{
  delay(1000);
  if(Serial2.available())
  {
    Serial.print("Number of bytes to read : ");
    Serial.println(Serial2.available(),DEC);
   
    while(Serial2.available())
    {
      // innermost statement of while loop is reading from USB, where is Serial2 processed?
      Serial.read();
    }

  }
}


The innermost while loop, reads from the USB on the MM but never extracts any characters from Serial2.
From the Wiki:
https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Maple-and-Maple-mini
Changes from the original version of Maple IDE

Some changes have been made to the API to make everything more compatible with the Arduino API

SerialUSB is now just called Serial
HardwareSPI is now called SPI and does not need to be instantiated as part of the sketch, as its instantiated as part of the SPI class when it is included via #include
Referenced to the BOARD LED and the BUTTON have been removed from the core headers because they only apply to the Maple and Maple mini


I have many Maple Mini (MM) examples here: https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/examples/MrBrunetteExamples
There have been some minor changes over time, the new ZIP is attached.

Ray
Attachments
GitHub_Examples.zip
(78.15 KiB) Downloaded 21 times

krishna
Posts: 7
Joined: Tue Apr 26, 2016 6:15 am
Location: Hyderabad,India

Re: Serial buffer

Postby krishna » Wed May 04, 2016 8:26 am

Thank you very much mrburnette,
Thanks for reply too..

krishna
Posts: 7
Joined: Tue Apr 26, 2016 6:15 am
Location: Hyderabad,India

Re: Serial buffer

Postby krishna » Wed May 04, 2016 8:27 am

Thanks for reply Grumpy.

krishna
Posts: 7
Joined: Tue Apr 26, 2016 6:15 am
Location: Hyderabad,India

Re: Serial buffer

Postby krishna » Wed May 04, 2016 8:30 am

Anyway mind quickly explaining why 63 bytes of receive buffer is not sufficient for your scenario ?


63 bytes of receive buffer is not sufficient for my scenario,
Even 127 bytes of receive buffer is not sufficient for my scenario.
any other solution?


Thanks,
Krishna.

User avatar
WereCatf
Posts: 167
Joined: Sat Apr 16, 2016 5:30 pm

Re: Serial buffer

Postby WereCatf » Wed May 04, 2016 8:37 am

krishna wrote:63 bytes of receive buffer is not sufficient for my scenario,
Even 127 bytes of receive buffer is not sufficient for my scenario.
any other solution?


Read the data more often and copy it to another buffer that you maintain yourself?

krishna
Posts: 7
Joined: Tue Apr 26, 2016 6:15 am
Location: Hyderabad,India

Re: Serial buffer

Postby krishna » Wed May 04, 2016 8:55 am

Thanks WereCatf for reply,

You also don't have more than 63 bytes in the receiver. The extra data that cannot be buffered is simply discarded.


But I am unable to read more then 63 bytes of data as Grumpy said.

User avatar
WereCatf
Posts: 167
Joined: Sat Apr 16, 2016 5:30 pm

Re: Serial buffer

Postby WereCatf » Wed May 04, 2016 10:08 am

krishna wrote:But I am unable to read more then 63 bytes of data as Grumpy said.


You must have misunderstood something. The buffer only holds 63 bytes, but if you keep reading the buffer's contents often enough so that it never gets full then nothing is lost. I mean, say, you have 50 bytes in the buffer waiting, meaning there's only room for 13 bytes more, then your sketch reads those 50 bytes and copies them to a bigger buffer, and POOF -- there's 63 bytes of room in the serial-buffer again for more data. You just keep reading whatever is in there and copying it to your bigger buffer and then do whatever it is you wanted to do with it.

Now, the bigger issue here is that you haven't explained what you're reading from the serial-port, or what you're planning on doing with it -- there are most likely better ways of going about this in the first place.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Serial buffer

Postby RogerClark » Wed May 04, 2016 10:09 am

krishna wrote:Thanks WereCatf for reply,


But I am unable to read more then 63 bytes of data as Grumpy said.


Do you mean that your code is not able to read the serial input very often.

i.e at 9600 baud (approx 900 chars per second), the 63 char butter will be full after 63/900 = 70mS

What processing are you doing that hangs the processor up for more than 70mS, that needs to run without a break for that long.

This really sounds like you have a software design problem.

I'd recommend you post some pseudo code to demonstrate why you can't read the Serial data very often

Edit .

@WereCatf

I think we posted at the same time.

I'm in agreement with you.


Return to “General discussion”

Who is online

Users browsing this forum: Baidu [Spider] and 3 guests