Custom bit length serial

Hi,
i am struggling with serial communication that uses 11 bits, 1 start, 8 data, 1 mode and 1 stop bit. The default is 1 pairity bit instead of the mode bit, but it seems i cant set this bit by myself.
Is there any way /library for sending custom length serial data?

Greetings Tarcontar

Are you struggling with receiving the data or sending it?

Paul

sending is the main issue at the moment,
currently i am trying to change the write method of Softwareserial.cpp to send an additional bit

Tarcontar:
sending is the main issue at the moment,
currently i am trying to change the write method of Softwareserial.cpp to send an additional bit

Back in the dark ages, we could set parity to always be 0 or always be 1. Guess that option was not implemented.

Paul

Maybe you could adapt the code in Yet Another Software Serial to meet your need.

...R

The USART in the 328 supports this, from the data sheet:-

• Supports Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits
• Odd or Even Parity Generation and Parity Check Supported by Hardware

So it would just be the matter of changing the right bits in the registers.

i found sth like that with registers etc, but with this sollution i would be forced to use a toolchain and raw c code with my mega, but i want to use the .ino files since i have a lot of other stuff to do also, stepper motors etc.
wouldnt be sending just another bit in the write method be enought? since its just a matter of setting tx high or low once again

thx for the replys

Tarcontar

wouldnt be sending just another bit in the write method be enought

No.

but with this sollution i would be forced to use a toolchain and raw c code with my mega,

No.
Just set the bits after the serial begin call.

1 mode and 1 stop bit

That is just 2 stop bits isn't it?

UCSR0B |= (1 << UCSZ02);

would that then be enough? or do i have to call the full initialization?

//set baud rate
UBRR0H = /(unsigned char)/(ubrr >> 8);
UBRR0L = /(unsigned char)/ubrr;
//Enable receiver and transmitter
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
//Set frame format: 8 data, 1 stop bit
UCSR0C = (3 << UCSZ00);
//Activates 9th data bit
UCSR0B |= (1 << UCSZ02);
//Activates interrupt upon reception
UCSR0B |= (1 << RXCIE0);
//Global Interrup Enable
sei();

and do i still have to modify the read/write methods?

would that then be enough?

I have not tried it myself but my expectation would be it would.

and do i still have to modify the read/write methods?

No

ok thx alot for your help so far,

but how do i write then 9 bits of data, simply write a uint16_t instead of an uint8_t?

You really, really need to consult the ATMega328 data sheet (or the one for whatever processor you are using).

From the data sheet:

20.6.2 Sending Frames with 9 Data Bit
If 9-bit characters are used (UCSZn = 7), the ninth bit must be written to the TXB8 bit in
UCSRnB before the low byte of the character is written to UDRn. The following code examples
show a transmit function that handles 9-bit characters. For the assembly code, the data to be
sent is assumed to be stored in registers R17:R16.

Tarcontar:
but how do i write then 9 bits of data, simply write a uint16_t instead of an uint8_t?

You don't need 9 bits of data, at least that is not what you said in the first post. Your mode bit of 1 followed by a stop bit is the same as two stop bits. Or you can have one stop bit and a parity bit.

If the mode bit is zero, you will need to use the 9th bit option described in the data sheet.

yes but i still need to set this mode bit, since it is only 1 if it is an address byte, at data bytes it is 0.

how can i setutp the usart for lets say tx1 and rx1 on arduino mega?

//set baud rate
UBRR0H = /(unsigned char)/(ubrr >> 8);
UBRR0L = /(unsigned char)/ubrr;
//Enable receiver and transmitter
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
//Set frame format: 8 data, 1 stop bit
UCSR0C = (3 << UCSZ00);
//Activates 9th data bit
UCSR0B |= (1 << UCSZ02);
//Activates interrupt upon reception
UCSR0B |= (1 << RXCIE0);
//Global Interrup Enable
sei();

do i just add the specific number at the end of these registers? e.g. UBRR1H etc?

Why bother posting if you don't read the replies?