Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Serial.available() and while(!Serial); #2123

Closed
ffissore opened this issue Jun 10, 2014 · 3 comments
Closed

Problem with Serial.available() and while(!Serial); #2123

ffissore opened this issue Jun 10, 2014 · 3 comments

Comments

@ffissore
Copy link
Contributor

The following "echo sketch" does not work as expected after #1953

void setup() {
  Serial.begin(9600);

  while (!Serial);
}

void loop() {
  if (Serial.available()) {
    Serial.print('-');
    Serial.print(Serial.read());
    Serial.print('-');
  }
}

It should print the code of each character given as input, sorrounded by two hyphens.
When started, you should see a blank IDE serial monitor. As soon as you type something, like "a", you should see printed
-97--10- (when using new line as line terminator)

Instead serial monitor will immediately display -0-, like I had given the null char as input.

Commenting line while (!Serial); prevents the error from happening.

This has been verified with a yun and with a leonardo

/cc @pbrook @embmicro @cmaglie

@ffissore ffissore changed the title Problem with Serial.avalable() and while(!Serial); Problem with Serial.available() and while(!Serial); Jun 10, 2014
@ffissore
Copy link
Contributor Author

Adding some details: I've used IDE from both ide-1.5.x and ide-1.5.x-avr-toolchain-gcc-4.8.1 branches
By reverting merges 82fe44d and 36331fa regression disappears.

@embmicro
Copy link
Contributor

This can be fixed by initializing peek_buffer to -1 on line 31 in USBAPI.h
int peek_buffer = -1;

#2124

@cmaglie
Copy link
Member

cmaglie commented Jun 13, 2014

Fixed with #2124

@cmaglie cmaglie closed this as completed Jun 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants