chipKIT® Development Platform

Inspired by Arduino™

Changing Com Port Settings.

Created Thu, 20 Apr 2017 09:06:05 +0000 by BobEdge


BobEdge

Thu, 20 Apr 2017 09:06:05 +0000

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.


majenko

Thu, 20 Apr 2017 09:17:14 +0000

You can only really change the baud rate through the Arduino API. Anything more complex you will need to manipulate the registers directly.

  • [url]http://ww1.microchip.com/downloads/en/DeviceDoc/61107F.pdf[/url]

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:

Serial.begin(57600);
U1MODEbits.PDSEL = 0b01;

Check the board documentation for which UART is mapped to which Serial instance.


BobEdge

Thu, 20 Apr 2017 10:00:29 +0000

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


majenko

Thu, 20 Apr 2017 10:13:22 +0000

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.