Pages: [1]   Go Down
Author Topic: Serial Commication RX/TX data bits 7 parity Even stop bit one  (Read 2536 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anybody know how to set databit 7 , parity Even, stop bit one????
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8067
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Those settings are in USART Control and Status Register 0 C (UCSR0C). 

The default value is 0x06 (0b00000110):
Asynchronous
Parity: None
Stop bits: 1
Data bits: 8

You want to set it to 0x24 (0b00100100):
Asynchronous
Parity: Even
Stop bits: 1
Data bits: 7

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 168
Posts: 12431
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

would be nice to have this in the standard serial lib's ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8067
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

would be nice to have this in the standard serial lib's ...

Nobody uses 7-bit anymore. smiley

The default 8-bit setting will work fine.  Just mask off the parity bit on receive and manually generate parity on transmit. smiley
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 168
Posts: 12431
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Nobody uses 7-bit anymore
Think the OP does ....

Sometimes you have old devices and sometimes you just want to squeeze out every bit in communication to win time. On the other hand if I need more speed I just put the baudrate @ 230400 (or up) between 2 Arduino's, works quite well and saves more time than 1 bit could smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote a library, SerialPort, to add extra features like character size, parity, error detection, and flexible buffer sizes.  It tries to be backward compatible with Arduino HardwareSerial, the C++ class for Serial.

The library is here http://code.google.com/p/beta-lib/downloads/list.  The file is SerialPortBeta20120106.zip.

There are a number of examples, Doxygen html documentation, and a readme file describing configuration options.

I implemented a fast serial datalogger with the SerialPort library and a new version of SdFat.  See this file: SerialLoggerBeta20120108.zip.

Edit: most options are specified in the begin call:
Quote
SerialPort::begin(uint32_t baud, uint8_t options = SP_8_BIT_CHAR)

Sets the data rate in bits per second (baud) for serial data transmission.

Parameters:
    [in]   baud   rate in bits per second (baud)
    [in]   options   constructed by a bitwise-inclusive OR of values from the following list.

Choose one value for stop bit, parity, and character size.

The default is SP_8_BIT_CHAR which results in one stop bit, no parity, and 8-bit characters.

SP_1_STOP_BIT - use one stop bit (default if stop bit not specified)

SP_2_STOP_BIT - use two stop bits

SP_NO_PARITY - no parity bit (default if parity not specified)

SP_EVEN_PARITY - add even parity bit

SP_ODD_PARITY - add odd parity bit

SP_5_BIT_CHAR - use 5-bit characters (default if size not specified)

SP_6_BIT_CHAR - use 6-bit characters

SP_7_BIT_CHAR - use 7-bit characters

SP_8_BIT_CHAR - use 8-bit characters

« Last Edit: January 14, 2012, 02:51:40 pm by fat16lib » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, some of us still have to work with older serial schemes.  I like the idea of just setting the control and status register to get me the 7Bit 1Start 1Stop EvenParity setting, but how do I tell it which serial port to apply the settings?  On my application I will be using three serial ports, but only one needs to be configured as above.

For that matter, how do I set a register?  It looks like all I have to do is:

UCSR0C = 0x24;

Is that correct?

G.
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 168
Posts: 12431
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@fat16lib

ambiguity in doc?

The default is SP_8_BIT_CHAR which results in one stop bit, no parity, and 8-bit characters.
SP_5_BIT_CHAR - use 5-bit characters (default if size not specified)

what's the default, or do I read it wrong?

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anybody know how to set databit 7 , parity Even, stop bit one????

Well if your using the standard arduino hardware serial, then:

Serial.begin(9600, SERIAL_7E1); should do it, of course changing the speed to what you actually require.

Lefty
Logged

Pages: [1]   Go Up
Jump to: