Go Down

Topic: Serial Commication RX/TX data bits 7 parity Even stop bit one (Read 3787 times) previous topic - next topic

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

johnwasser

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

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

robtillaart

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

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

johnwasser


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


Nobody uses 7-bit anymore. :)

The default 8-bit setting will work fine.  Just mask off the parity bit on receive and manually generate parity on transmit. :)
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

robtillaart

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 :)
Rob Tillaart

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

fat16lib

#5
Jan 14, 2012, 08:39 pm Last Edit: Jan 14, 2012, 08:51 pm by fat16lib Reason: 1
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


gcw1957

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.

robtillaart

@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?

Rob Tillaart

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

retrolefty


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

Go Up