Pages: [1]   Go Down
Author Topic: Arduino, Serial.write & Serial.read?  (Read 246 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. On Arduino, does the Serial.read function read from the serial buffer from its on board buffer, or the buffer on the other Arduino that is connected to the rx pin? Same goes for Serial.write. Does it write on its own buffer, or write on the other Arduino's buffer? After I read a data, does it automatically flush the buffer? The Serial.read() and Serial.write() page doesn't tell me anything regarding serial buffer. Thanks!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. On Arduino, does the Serial.read function read from the serial buffer from its on board buffer, or the buffer on the other Arduino that is connected to the rx pin? Same goes for Serial.write. Does it write on its own buffer, or write on the other Arduino's buffer? After I read a data, does it automatically flush the buffer? The Serial.read() and Serial.write() page doesn't tell me anything regarding serial buffer. Thanks!

The serial read and write buffers are SRAM locations in the chip running your sketch. Upon reading a character with a serial.read command the serial library manipulates the SRAM memory address buffer pointer(s) such that the character will never be seen again by any future serial.read command, just newer arriving characters if they are ready to be read. Same goes on for the transmit buffer manipulation. The buffering is suppose to be pretty much transparent to your coding requirements. serial.available will return a count value of number of characters ready to be read but it's up to you to read them out one at a time. If you fail to read characters fast and often enough to keep the buffer from filling up the buffer pointers will wrap around and start writing over characters that you haven't yet read.

Lefty
Logged

Pages: [1]   Go Up
Jump to: