Serial1 and so on

Hallo all,

I have a quick question, I couldn't find a direct answer in duckduck.

Is it safe to assume that the Mega has four distinct Serial buffers of 64Bytes each? Can the buffer overflow?

No - and of course it has 8 not four.

Mark

The source code for hardware serial is in the IDE installation folder. On my machine it is at E:\arduino-1.8.5\hardware\arduino\avr\cores\arduino. The buffer sizes are set in the HardwareSerial.h file.

Receive buffer can overflow (characters are lost if it fills up and then gets another character).

If you fill up the transmit buffer, writing to the serial port will become blocking (ie, it will wait until there is space in the buffer) until there’s room in the buffer.

Receive buffer can overflow

No, it can't. If the buffer is full, data is thrown away. It is not written beyond the end of the array, which would be my definition of overflow.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

As written the examples assume a maximum of 32 characters but you can extend that as much as you want by changing the value of numChars.

...R

Kevin77:
Is it safe to assume that the Mega has four distinct Serial buffers of 64Bytes each? Can the buffer overflow?

If we talk from low level hardware point of view, the ATmega2650 MCU (used in Arduino MEGA) has no buffer to store incoming or outgoing data. Data arrives as a byte (8-bit) over a 10-bit wide frame; after validity check, the data byte enters into the Receiver Register. The user program must read the data byte (using polling or interrupt strategy) from the receiver register; else, it will be lost being over-written by the next incoming valid data byte.

From high level point of view (the Arduino IDE Platform), there is an 64-byte wide FIFO type data buffer created in the RAM space of the MCU, which can store as many as 63-byte incoming data (last byte is a null-byte). As the data byte arrives, it interrupts the MCU; the MCU reads the data byte from the Receiver Register and stores it in the FIFO buffer.

holmes4:
No - and of course it has 8 not four.

Mark

with 8 you mean 4x for Receiving and 4x for receiving?

Kevin77:
with 8 you mean 4x for Receiving and 4x for receiving?

No. Four for receiving and 4 for sending.

PaulS:
No. Four for receiving and 4 for sending.

Ah yes of course that is what I meant.

But thanks for pointing it out...