Serial.begin(speed, config) not compiling for Leonardo Board

Posted by forgemo on Stack Overflow See other posts from Stack Overflow or by forgemo
Published on 2012-12-08T02:11:56Z Indexed on 2012/12/08 11:07 UTC
Read the original article Hit count: 305

Filed under:

I would like to configure my serial communication to have no parity, 1 start- and 2 stop-bits.

The documentation for Serial.begin(speed, config) states:

(...) An optional second argument configures the data, parity, and stop bits. The default is 8 data bits, no parity, one stop bit.

The documentation also lists the possible configuration-values. According to my (limited) understanding, I need SERIAL_7N2 or SERIAL_8N2 to meet my requirements. (I'm not sure how the data-bits relate to the the 1-start-bit that I need.)

However, I can't even compile because I have no idea how to supply that config value to the begin method. (I don't have much Arduino/C++ experience)

I've tried in my code the following two variants:

Serial.begin(9600, SERIAL_8N2);
Serial.begin(9600, "SERIAL_8N2");

Am I missing something?

Additional Information:

Serial.begin(speed, config) has been introduced with the latest Arduino 1.0.2 IDE version.

The code defining/implementing the begin methods can be found here.

HardwareSerial.h HardwareSerial.cpp

Edit:

According to the replies from PeterJ and borges, the following variant is correct.

Serial.begin(9600, SERIAL_8N2); 

However, it's still not working.

I found that the compile error doesn't occur if I change the configured board from my Arduino Leonardo to Arduino uno.

Therefore, it could be a bug occurring only with a subset of boards ... or maybe it's not supported?!

© Stack Overflow or respective owner

Related posts about arduino