Go Down

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

ender_2387

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: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

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: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

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

Artronix

Hello,

Would it be possible that anyone give a working example please?

I have manage to make it work in Java but I am new to Arduino and seems this is the only topic online related to 7 bit.


Code in Java:
(9600, SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_EVEN);

Thanks in advance

Tronix

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Artronix

Hi Awol,


I have tried SERIAL_7E1 as suggested above.

void setup() {

Serial.begin(9600,SERIAL_7E1);

}

void loop() {
               Serial.println(Serial.read());
        }

However the Serial monitor display garbage.

https://postimg.org/image/6s3btm0i9/


Any idea please?


It works fine with Java Code connected to Computer RS232 port.
I am connecting direct Arduino to com port RX / TX / GND of the device.


Thanks

Tronix



Artronix

Anyone can help please ?

My device is a Multimeter with serial port.

Do I require a TTL converter ?

Thanks

Tronix

AWOL

My device is a Multimeter with serial port.

Do I require a TTL converter ?

Yes.
Or maybe no.

How can we tell?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Artronix

Good question but since I am a newbie cannot answer it that's why I am asking here.

When I connect it to the Arduino Uno direct (using just wires) the TX Blinks every 1 sec so some sort of data is passing and from the serial monitor some numbers appear.

Connect it direct to PC Com port works fine but if possible I need this to work with Arduino.

Regards

Tronix


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy