Changing Com Port Settings.

Post Reply
BobEdge
Posts: 7
Joined: Wed Dec 07, 2016 11:24 am

Changing Com Port Settings.

Post by BobEdge » Thu Apr 20, 2017 10:06 am

Hello,

I need to send, & receive data via the hardware serial port, with the following settings: Parity Even, Data Bits 8, Baud 57600, Flow Control None, Stop Bits 1.
I can't find any information on changing the com port settings in Arduino.
Is it possible to change these settings easily?

Many thanks
Bob.

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Changing Com Port Settings.

Post by majenko » Thu Apr 20, 2017 10:17 am

You can only really change the baud rate through the Arduino API. Anything more complex you will need to manipulate the registers directly.
The UxMODE's PDSEL bits select the data format - 0b01 = 8-bit data, even parity. For UART1 (which is the default Serial on, for example, the Uno32), it would be:

Code: Select all

Serial.begin(57600);
U1MODEbits.PDSEL = 0b01;
Check the board documentation for which UART is mapped to which Serial instance.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

BobEdge
Posts: 7
Joined: Wed Dec 07, 2016 11:24 am

Re: Changing Com Port Settings.

Post by BobEdge » Thu Apr 20, 2017 11:00 am

Thank you very much majenko, you legend.

The arduino documentation is once again wrong or out of date. they say "Serial.begin(57600, SERIAL_8E1);" would do it, but just gives errors.

I was wondering how to directly change the PIC registers. I'm sure this knowledge will prove to be very useful in the future, or dangerous :D

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Changing Com Port Settings.

Post by majenko » Thu Apr 20, 2017 11:13 am

The Arduino's variant of Serial.begin() is slightly different to ours. Chiefly because the AVR chips can support a wide range of very strange settings that we can't - things like 5N1. Since 99.999% of all communication is 8N1 anyway there's little need for it, and doing it manually is no real chore after all.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply