Pages: [1]   Go Down
Author Topic: is there an "serial.print"-output buffer (UNO rev3)? [SOLVED]  (Read 597 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My question is with the Serial.print(data) command.

When it comes to Serial communication (with a chip with only 1k ram as the uno) the question of buffers is quite prominent. I for instance am aware that I have a 3character/byte UART input buffer and a -i think- 128byte input buffer by the HardwareSerial buffer
(like well explained here http://binglongx.wordpress.com/2011/10/26/arduino-serial-port-communication/)

My question is. What is with the outgoing data?
I can imagine that I can produce data faster than it can be shuffled away via a 9600baud rate?

Code:
void loop()
{
   Serial.print("A");
}

at 16Mhz this loop should be repeated quite easily more than 20'000 times per second.
(assuming hereby that 16Mhz = 16'000'000 operations per second => the loop would need 800 operations to run, which I doubt for the simple one-line command).
=> It seems to me that the Arduino would at 9600 bps baud rate would fail here?

is this right?

a) What happens then. does it crash and "reboot" ?
b) Does it depleat the ram?
c) does it simple discard excess data? (if so which data is discarded, the earlier or the later one?)

thank you for your insights!


BTW:
this is not very much relevant to my question.
But maybe it has a slight impact so I want to mention
that I use Linux and /dev/ttyACM0 to communicate via the command line.
so the data arriving would arrive there.
=> also, I just want to mention that I do not use the IDE (because I dislike the Java-shit "security risk"... so I code using makefiles and communication to the Arduino is done via /dev/ACM0)



« Last Edit: March 09, 2013, 07:58:49 am by alexander_senseo » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26250
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
at 16Mhz this loop should be repeated quite easily more than 20'000 times per second.
Up until the point that the output serial buffer is filled, yes, then you will slow to a roughly 960Hz loop rate.

Edit: Sorry - hit "post" too soon. The input and output buffers are both 64 bytes.
Once the output buffer is full, your loop would slow to the line rate; as one character is transmitted, another is accepted into the output buffer, so your loop blocks.
« Last Edit: March 07, 2013, 04:53:06 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the information AWOL.

I confess that I was rather surprised by that outcome. It makes sense, but I must say beforehand I was inclined to believe that the result would rather be a crash when the buffer is depleated.

That is... when using the Arduino IDE and its tools it can be that the PC-side (of the serial connection) really receives the data. But I am not sure ...

(NEW doubt)?? what if there is a blockage there? Is is independent of the "receiving-PC side" (no matter linux/windows etc) that the data is moved of? Or can the receiver cause a blockage (no matter the baud rate).

my new doubt is founded in the experience/test that if I have arduino do something like

Code:
#include <Arduino.h>

int counter;
void setup()
{
  counter=1;
  Serial.print("I start\n");
}

void loop()
{

 Serial.print("counter=");
 Serial.print(counter,DEC);
 Serial.print("\n");

}

and I do not "listen" at the serial side
(in linux I would do so via:
Code:
cat /dev/ttyACM0
)
then I perceive that arduino kind of restarts again.

So it really seems to me a doubt. "What happens if the receiver is blocking?" / can that happen? / should that happen? (no...but)

thanks for the input






Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26250
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure what you're asking - the Arduino doesn't know or care if there is nothing "listening" - once a character has gone from the hardware transmit register, it's gone - there is no handshaking.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the additions you have made to your first reply!

You mention that "arduino" does not care where the data goes?
well, what would happen if the user side "breaks" the Serial connection?

Would that lead to a "restart"/crash of the arduino?

More general? where would I look such a stuff up myself? The references are somewhat short... (at least that is at the moment my impression)

UPDATE:
never mind I found that:

http://arduino.cc/forum/index.php/topic,144827.msg1087733.html#msg1087733

I was assuming there is a "output"-buffer overrun cause the ram to deplete and BANG reboot
instead each time a serial conneciton is "opened" the arduino is rebootet

This is somewhat counter-intuitive... and caused me to think all the stuff in the first place

« Last Edit: March 07, 2013, 05:26:53 am by alexander_senseo » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26250
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
each time a serial conneciton is "opened" the arduino is rebootet

This is somewhat counter-intuitive..
It may be counter intuitive, but it is one of the things that makes the Arduino' bootloader so easy to use.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote
each time a serial conneciton is "opened" the arduino is rebootet

This is somewhat counter-intuitive..
It may be counter intuitive, but it is one of the things that makes the Arduino' bootloader so easy to use.

Yes, that may be smiley
As long as it is documented, there is no harm / confusion caused.....
I must have missed it that in the Reference that talks about the Serial Connection the fact "reboot at each connection" is mentioned...

thank you for the explenations

Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When it comes to Serial communication (with a chip with only 1k ram as the uno) the question of buffers is quite
The Uno has 2k of RAM.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote from: alexander_senseo on March 07, 2013, 09:32:06 AM
Quote
When it comes to Serial communication (with a chip with only 1k ram as the uno) the question of buffers is quite
The Uno has 2k of RAM.

Thank you! Sure thing...
I have got it mixed up with the EEPROM size which I think is 1k....
Indeed 2k already gives me much more space... great!
Logged

Pages: [1]   Go Up
Jump to: