7 years, 6 months ago.

can't detect enter key on serial PC

This seems to be really basic but it's not working. I'm simply reading the input from a user over a serial console and want to see if he pressed the enter key but the key is not being detected. The other keys work though

  1. include "mbed.h"

Serial pc(USBTX, USBRX);

int main() {

char c; while(1) {

c = pc.getc(); if (c == '\n') pc.printf("You pressed enter");

} }

What you get will depend on your terminal application and its settings. You would normally receive CR (\r or 0x0d) although there may be an option turning this into \r\n (0x0d 0x0a) but in your case that does not seem to be the case. You can also just print out what you receive using a %02x printf format to find out.

posted by Peter Holzleitner 14 Jul 2013

3 Answers

1 year, 6 months ago.

c == '\r' might work

Accepted Answer
7 years, 6 months ago.

What SW do you use for terminal communication? Check settings at "append".

I tried PuTTY and there was a problem with this, but in Termite 2.9, which is my favorite (google it), it works well. (There i have "Append LF" in settings)

7 years, 6 months ago.

I'm not sure I understand what you're telling me. I'm using serial port from the terminal application of my mac. I just put the command screen /dev/tty.device to connect to my device that's all I know.