RESOLVED-How do I set DataBits & Parity on MEGA serial ports w/four USARTS?

Solution is:

Serial1.begin(9600,Serial1_7E1);

Hi - I have an UNO and know how to set data bits and Parity on the UNO USART
To configure 7 databits and Even parity:

UCSR0C = (2<<UPM00)|(0<<USBS0)|(2<<UCSZ00)|(0<<UCPOL0);

I've purchased a MEGA 2560 which has four USARTS. Cannot find a doc that shows how to configure them individually.

Is the following a correct assumption?

Serial
UCSR0C = (2<<UPM00)|(0<<USBS0)|(2<<UCSZ00)|(0<<UCPOL0);

Serial1
UCSR1C = (2<<UPM00)|(0<<USBS0)|(2<<UCSZ00)|(0<<UCPOL0);

Serial2
UCSR2C = (2<<UPM00)|(0<<USBS0)|(2<<UCSZ00)|(0<<UCPOL0);

Serial3
UCSR3C = (2<<UPM00)|(0<<USBS0)|(2<<UCSZ00)|(0<<UCPOL0);

I saw one thread that indicated the # in the UCSR#C command referred to the individual USARTs. However, that thread showed:

Serial1
UCSR2C = (2<<UPM00)|(0<<USBS0)|(2<<UCSZ00)|(0<<UCPOL0);2 // UCSR#C does not match Serial#.

Any guidance appreciated. Don't want to blindly submit a command without understanding and brick a $60 MEGA.

Thanks !

What version of the IDE are you using? 1.0.3 (I think) added an optional second argument to the Serial.begin() method that allows tailoring of bits and parity.

Thanks for responding so quickly! I have IDE V 1.0.4. I looked into the Serial.begin(speed); command but found no further parameters to add.
Your suggestion makes sense. Adding additional parameters to the Serial.begin command also makes perfect sense.

I'll start a search for further info based on that.

Thanks!

p.s. Unrelated: Sorry to hear about the bridge collapse in WA. Aside form the injuries, it can't be good for travelers and daily commuters.

JayStel:
Thanks for responding so quickly! I have IDE V 1.0.4. I looked into the Serial.begin(speed); command but found no further parameters to add.
Your suggestion makes sense. Adding additional parameters to the Serial.begin command also makes perfect sense.

I'll start a search for further info based on that.

Thanks!

p.s. Unrelated: Sorry to hear about the bridge collapse in WA. Aside form the injuries, it can't be good for travelers and daily commuters.

The details of setting addition serial parameters (as of 1.0.4) are in the arduino reference for serial.begin:

So for you needs you could use:

Serial.begin(speed, SERIAL_7E1) 
Serial1.begin(speed, SERIAL_7E1) 
Serial2.begin(speed, SERIAL_7E1) 
Serial3.begin(speed, SERIAL_7E1)

Lots easier then fooling around with direct register control bits. :wink:

Lefty

Google search # 2 gives this:

There are serial config parameters as you explained. Unfortunately for me, the syntax has no example and makes no sense.

Here is what I understand from that document:

Serial1.begin(9600,SERIAL_7N1); // Should give me 9600,7,E,1,

I tried it in the Sketch and it did in fact compile and upload to the MEGA without errors. It will be a few hours before I can test it on the actual serial device (BetaBrite LED scrolling display). But I will post the results here.

WOW. That sure is soo much easier than setting the config registers..

Thank you, very much!
Much regards,
John

Thank you Lefty - Your solution is what I just now found. Perfect!

Regards,
John

JayStel:
Google search # 2 gives this:

Serial.begin() - Arduino Reference

There are serial config parameters as you explained. Unfortunately for me, the syntax has no example and makes no sense.

Here is what I understand from that document:

Serial1.begin(9600,SERIAL_7N1); // Should give me 9600,7,E,1,

I tried it in the Sketch and it did in fact compile and upload to the MEGA without errors. It will be a few hours before I can test it on the actual serial device (BetaBrite LED scrolling display). But I will post the results here.

WOW. That sure is soo much easier than setting the config registers..

Thank you, very much!
Much regards,
John

No, Serial1.begin(9600,SERIAL_7N1); // would give you 7= seven data bits, N= no parity bit, 1= one stop bit

Serial1.begin(9600, SERIAL_7E1); // would get you 7 data bits, one even parity bit, one stop bit.

Lefty

Lefty - Yup. I caught that when typing it in. It is set for 7E1.

Unfortunately, it did not work. I put the sketch back on the UNO, using the appropriate commands - setting the Config register for UART etc. And it works again.

The debug-status println commands in the sketch (to monitor progress) do show up on the Terminal Monitor(via USB). I have a Commitment until 9:30Eastern and will pick it up after that. Must be a type-O in my sketch. Other than the one you pointed out. That was fixed.

REgards,
John
(I edited this post to fix a confusing sentence (20:51 Eastern)

Resolved - I had tx and rx reversed on Serial1 of the MEGA. Got used to Rx being on the lower pin # from working with UNO Serial.

Setting speed, databits, with

Serial1.begin(9600,Serial1_7E1);

Works perfectly.

Thanks All for your help.

John