Serial buffer question

I am using the Arduino Ethernet as a serial converter from RS485 to ethernet. Basically, data is being sent via RS485 from a device to the arduino + RS485 shield, which has the TX and RX for RS485 connected to pin 0 and 1 on the Arduino ethernet. Data is sent three times a second. My question is if serial buffer fills, does it get overwritten with new data regardless if data is read from the buffer using Serial.read(), or does the buffer fill up and not receive new data?

If one byte is written from the buffer, and more data is received, how is the buffer setup, is it FIFO? If so, then the new data would be added to the end of the buffer and the next byte read would be the second byte from the original set of data, assuming that the serial buffer is not overwritten if new data is received faster than the buffer can be read.

Thanks.

My question is if serial buffer fills, does it get overwritten with new data regardless if data is read from the buffer using Serial.read(), or does the buffer fill up and not receive new data?

If the buffer is full, the new data is discarded.

If one byte is written from the buffer

You don't write from a buffer. You read from a buffer, or you write to a buffer.

how is the buffer setup, is it FIFO?

Yes. Except when the buffer is full. Then, it is NINO (not in, not out).

If so, then the new data would be added to the end of the buffer and the next byte read would be the second byte from the original set of data, assuming that the serial buffer is not overwritten if new data is received faster than the buffer can be read.

The next byte read is always the first byte in the buffer.

The Serial functions use a circular buffer. The data in the buffer is not moved up as a read occurs. The pointer to the next byte is simply moved forward one character. As data is written to the buffer, the pointer to the next position to write to is moved backwards one character. There is logic to test that the read pointer and write pointer never cross.

If one byte is written from the buffer

You don't write from a buffer. You read from a buffer, or you write to a buffer.

Sorry, I meant to say if one byte is read from the buffer.

If so, then the new data would be added to the end of the buffer and the next byte read would be the second byte from the original set of data, assuming that the serial buffer is not overwritten if new data is received faster than the buffer can be read.

The next byte read is always the first byte in the buffer.

The Serial functions use a circular buffer. The data in the buffer is not moved up as a read occurs. The pointer to the next byte is simply moved forward one character. As data is written to the buffer, the pointer to the next position to write to is moved backwards one character. There is logic to test that the read pointer and write pointer never cross.

So just so that I am clear, if one byte is read, and the buffer is full, the next byte received in the buffer is placed in the first buffer byte location, correct. My concern is that if data is received while reading data from the buffer, the order of the data will be corrupt.

So just so that I am clear, if one byte is read, and the buffer is full, the next byte received in the buffer is placed in the first buffer byte location, correct.

No. Think of a ferris wheel. Passengers are loaded into a car (data is added to the next position in the buffer). Passengers are unloaded from the next car, assuming that the wheel is full.

When a read occurs, the read pointer is moved. That increases the distance between the read pointer and the write pointer.

When a write occurs, the write pointer is moved. That decreases the distance between the read pointer and the write pointer.

My concern is that if data is received while reading data from the buffer, the order of the data will be corrupt.

Reading from the buffer causes interrupts to be suspended while the read pointer is repositioned. No data can be written while that happens.

The buffer is a FIFO queue. Data is added to one end, if there is room, and removed (read) from the other end.