Theoretically, I know that UART buffer size is 64 which means, it can store up to 64 characters coming from INPUT BOX of Serial Monitor. The following sketch shows that I can catch only 63 characters coming from INPUT BOX implying that buffer size is 63. I would appreciate if someone clarifies the case.
void setup()
{
Serial.begin(9600);
L1: byte n = Serial.available();
if ( n != 64) // works for n != 63
{
goto L1;
}
Serial.println(n);
}
void loop() {}
@b707 actually implies that you should collect data when it becomes available; not wait till you have 64 bytes in the serial input buffer and then read them all.
Your sketch works well; but, it does not answer to my query as you always clear the buffer by reading a character as it arrives. I want to read all the 64 characters once they are accumulated. (There are two typo mistakes in sketch of post #6 which I have corrected.)
Using goto statement, the OP observes visually that the program control is reverting to his designated label. The following equivalent codes do the same thing with a little bit of abstraction.
void setup()
{
Serial.begin(9600);
while (Serial.available() != 63)
{
;
}
for (int i = 0; i < 63; i++)
{
Serial.print((char)Serial.read());
}
}
void loop() {}
Thank you. This article actually contains the answer to my query of knowing that if the buffer size is 63 or 64. Now, I know that it's a circular buffer and the actual capacity is N-1 = 64-1 = 63.
I don't want to process 64 characters at once; rather, I want to know through experiment that the serial buffer has 64 locations to hold 64 characters.
The HardwareSerial.h says that --
We're
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
#define SERIAL_RX_BUFFER_SIZE 64
#define SERIAL_TX_BUFFER_SIZE 64
Nowhere is told that the actual capacity is N-1 bytes. It is only the experiment through which the OP has discovered the fact which has been supported by post #8@awneil.