Reading 9E2 serial frame format

Hello,

I need to communicate with a device with a not so typical serial frame format.

It uses 9 data bit, 2 stop bit and even parity format. I can actually ignore info of 9th data bit but I need to communicate with that frame format.

As far as I know, this configuration is not supported by default Serial library.

https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/

Did someone have a similar situation or can recommend a solution, how could this be done?

Thanks in advance.

I do not think that that configuration is supported by the hardware, in which case it will not be supported by Serial. You may have to modify Software Serial, or connect and use other hardware with your Arduino.

That is a fairly weird configuration. I hope that you are really certain about it.

Perhaps the OP thinks the start bit is a data bit, since it is not mentioned in the list of bits.

Paul

If you need 9 bit serial, you can’t do that with the builtin Serial… Hardware supports it, but Serial does not.

HOWERVER, since you say you don’t need that last bit, I think you can make that work by doing Serial.begin() with the baud rate and 8E2.

Then, do

UCSR0B |= 1<<UCSZ02;

to put it into 9-bit mode.

The Serial class won’t be aware of the 9th bit, and won’t read it - but if you don’t need it, and it’s okay that you always send 0 as the last bit, it might work.

Otherwise, you’re looking at a more complicated task.

DrAzzy:
Otherwise, you're looking at a more complicated task.

Thank you for a reply.

I was digging a little more and found this custom library of @nickgammon

Let me be sure I understand you data format.

You state "It uses 9 data bit, 2 stop bit and even parity format. I can actually ignore info of 9th data bit but I need to communicate with that frame format.".

Then I repeat in bit order: Start bit, 9 data bits, 1 parity bit, 2 stop bits.

IS that correct?

Paul

Paul_KD7HB:
IS that correct?

Yes, that's right.

This circuit should act like a serial converter between two devices with two different frame formats. First device have 9E2 frame format, the second one has 8N1 frame format.

The plan is to use ATtiny441, which have 2 UARTs.

First UART would read data with serial frame 9600, 9bit, 2 stop bits, even parity and send data to second UART with 9600, 8N1 frame format.

Data of 9th bit can be ignored since it is irrelevant for second device to work but the frame should remain the same.

It should also go vice versa, sending through 9N2. In that case, the 9th bit can be 0.

You must plan to buffer as, even at the same baud rate, one line will send/receive faster than the other.

Paul

Paul_KD7HB:
You must plan to buffer as, even at the same baud rate, one line will send/receive faster than the other.

Speed in not so important (from one device to another). I can collect everything from one side first and than send next.

I am concerned about how to establish proper packet frame (9E2).