Serial Commication RX/TX data bits 7 parity Even stop bit one

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

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

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

robtillaart:
would be nice to have this in the standard serial lib’s …

Nobody uses 7-bit anymore. :slight_smile:

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

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

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:

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

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.

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

ender_2387: 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

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

Have you read this?

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

Anyone can help please ?

My device is a Multimeter with serial port.

Do I require a TTL converter ?

Thanks

Tronix

Artronix: My device is a Multimeter with serial port.

Do I require a TTL converter ?

Yes. Or maybe no.

How can we tell?

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

Even as a newbie, you must know that we cannot see what you can see.

So, why don't you share some details?

If it (whatever "it" is (there's a hint there)) works when you plug it into a PC (which most likely uses RS232 levels), then yes, it seems likely that you're going to need an adapter.

If it works connected "directly to a PC", it will need some kind of converter in order to be connected directly to the arduino...

Thanks for the reply.

There is not much details more then I shared already.

Its a multimeter model UNI-T UT61D.

It uses 7 parity Even stop bit one.

A converter something like this ? http://img.dxcdn.com/productimages/sku_132934_2.jpg https://daverobertson63.files.wordpress.com/2013/06/arduino_rs232.png

Circuit diagram https://www.avrprogrammers.com/images/programmers/max-232.png

Regards

Tronix